Question

I am writing a c code and using case switch statement for the gas type to...


media%2Fa7c%2Fa7ca52b4-802e-4952-ab5d-cfI am writing a c code and using case switch statement for the gas type to give me variables a and b in my equation for pressure. I am confused on how to use user defined function that it is asking for in the bullet points
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>


void print_list(void){

   printf("%15s%15s%15s%15ds\n", "GasType","Gas","a(L^2-atm/mol^2)", "b(L/mol)");
   printf("%15s%15s%15s%15ds\n", "1","Heleium,He","0.0341", "0.0237");
   printf("%15s%15s%15s%15ds\n", "2","Hydrogen,H2","0.244", "0.0266");
   printf("%15s%15s%15s%15ds\n", "3","Oxygen,O2","1.36", "0.0318");
   printf("%15s%15s%15s%15ds\n", "4","Chlorine,Cl2","6.49", "0.0562");
   printf("%15s%15s%15s%15ds\n", "5","Carbon dioxide,CO2","3.59", "0.0427");
}

double presure_cal(int gas_type, double T, double V, double n){
    double a[5];
    double b[5];
    double value;
    a[0] = 0.0341;
    a[1] = 0.244;
    a[2] = 1.36;
    a[3] = 6.49;
    a[4] = 3.59;
    b[0] = 0.0237;
    b[1] = 0.0266;
    b[2] = 0.0318;
    b[3] = 0.0562;
    b[4] = 0.0427;

   
    value = (0.08206 * T)/((V/n)-b[gas_type-1]) - a[gas_type-1]/((V/n)*(V/n));
    return value;
}

int main(){

    char c;
    double a[5];
    double b[5];
    int n;
    double qty;
    double temp;
    double ivol;
    double fvol;
    double incr;

   


   do {
    printf("%-30s %-30s\n","Number","Gas Type");
    printf("%-30s %-30s\n","1","Helium");
    printf("%-30s %-30s\n","2","Hydrogen");
    printf("%-30s %-30s\n","3","Oxygen");
    printf("%-30s %-30s\n","4","Chlorine");
    printf("%-30s %-30s\n","5","Carbon dioxide");
       do {
           printf("Enter Gas number(1,2,3,5 or 5)>>");
           scanf("%d",&n);
       } while (n <1 || n >5);
       printf("Enter Quantity of gas (in moles)>>");
       scanf("%lf",&qty);
       printf("Enter temperature (in Kelvin)>>");
       scanf("%lf",&temp);
       printf("Enter initial volume (in liters)>>");
       scanf("%lf",&ivol);
       printf("Enter final volume (in liters)>>");
       scanf("%lf",&fvol);
       printf("Enter volume increment(in liters)>>");
       scanf("%lf",&incr);
       c = getchar();
       printf("%-25s %-25s\n","Volume(liters)","Presure(atm)");
       while (ivol <= fvol+incr){

            printf("%-25lf %-25lf\n",ivol,presure_cal(n,temp,ivol,qty));
            ivol = ivol + incr;
       }
      
       printf("Do you want to continue(y or n)?");
       c= getchar();
   } while (c != 'n');
   
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
I am writing a c code and using case switch statement for the gas type to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am writing a code in c for windows. It should be very very basic. The...

    I am writing a code in c for windows. It should be very very basic. The instructions say to use a switch case statement for processing the user input to the menu. Also I prefer the main to be at the top. Should be very basic and simple. a) Print your name. b)  Prompt the user to enter a positive number between 1-50, read the entered input, and display all numbers from 0 up to the number entered (the display should...

  • I am writing a program in c programming and it is supposed to do the following using mc9s12dg256.h microcontroller When...

    I am writing a program in c programming and it is supposed to do the following using mc9s12dg256.h microcontroller When both DIP switches #8 and #1 are high, turn on all LEDS. When both DIP switches #8 and #1 are low, turn off all LEDs When DIP switch #8 is high and #1 is low, turn on all the even numbered LEDs. When DIP switch #1 is high and #8 is low, turn on all the odd numbered LEDs. Your...

  • I am writing a program in C++, which requires me to read an input text file...

    I am writing a program in C++, which requires me to read an input text file using command line argument. However, I am using xcode on my Macbook to write C++ program, and use terminal instead of command. How do you use int main(int argc, char** argv[]) to read an input file. My professor requires us not to hard code the text file name like .open("example.txt"); Thank you!

  • I am writing C++ code, and I need help for this. Create a program that will...

    I am writing C++ code, and I need help for this. Create a program that will convert a decimal value into Roman numeral, and output the result. The program will ask for an integer input, assume all inputs are valid, and the program should not end unless the user tells you to. C++ code.

  • I want c++ code for employee payslip calculation using switch statement convert this code to switch...

    I want c++ code for employee payslip calculation using switch statement convert this code to switch statement also, use for loop ___________________________________________________________________________ #include using namespace std; int main() {char empname[222]; float basicSalary, h_r_a, DearnessAllow, tax, netSalary; int e_id; cout<<"\nEmployee Name :"; cin>>empname; cout<<"\nEmployee Id :"; cin>>e_id; cout << "Enter Basic Salary : "; cin >> basicSalary; DearnessAllow = 0.30 * basicSalary; h_r_a= 800; tax = 0.10 * basicSalary; netSalary = basicSalary + DearnessAllow + h_r_a - tax; cout<<"\nEmployee Id              :...

  • I need help writing a C programming code. I am trying to create a program that...

    I need help writing a C programming code. I am trying to create a program that returns ANY given number's decimal value as an Integer (Whole number). Examples: User input: 0.35 Output: 35 User input: 1.465 Output: 465 User input: 10.6054 Output: 6054

  • I am working on this switch statement code and I am getting errors. Please help. import...

    I am working on this switch statement code and I am getting errors. Please help. import java.util.Scanner; public class Switchstatement { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here } class Convertor { public static void main(String[] args) {    int choice;    Double Yen, UsDollars, Kilometer, Miles, Kilograms, Pounds, Inches; Double Centimeters, result;       Scanner scanner = new Scanner(System.in);    System.out.print("Enter 1\t UsDollars to Yen:...

  • Hi I need some help writing a security code using python mongodb restful api. I just...

    Hi I need some help writing a security code using python mongodb restful api. I just need help on how to provide a security login to user to enter their username and password or to have a block in using extra access once they have logined and they want more access to the databases they will be force to sign out of the server but I just do not know how to start on it can someone show me how...

  • I am writing chemical formulas using elements and I have to name them. I am getting...

    I am writing chemical formulas using elements and I have to name them. I am getting confused as to when to use the prefix because sometimes they are omitted. For example if given N^4+ O when you name it it becomes NO2 (nitrogen dioxide ) where did the number 4 go and why did O gain a number 2

  • I am writing python code. I submitted an assignment but the professor said it was a...

    I am writing python code. I submitted an assignment but the professor said it was a modularization. Can you help me see what part of the code is modularization? Pseudocode: 1. Decalre MainMethod () function: # A. Parameters: Three numbers # B. Put the three numbers in reverse # 2. Main Program # A. Initialize Varibles # B. Accepts three values from the user # C. Invoke MainMethod () function, passing the three numbers as arguments in reverse # D....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT