Thread: Need help with if statements and switch statments

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    18

    Need help with if statements and switch statments

    I'm working on a program for my class which requires us to create an Ideal Gas Law solver using if and switch commands. The program should ask the user which variable they want to solve for: pressure, temperature or volume. After picking which one, the program should ask for the other two in appropriate units. I've continued working on the program when I ran into an issue. I've also included a few default gasses with their corresponding molar masses and a 6th option for the user to input their own molar mass but rather than redirecting a user to input their own molar mass it goes straight to asking for the variable input and I can't figure out how to get around this issue. I'm fairly new to C++ and stumbled on this forum for help. I'm not asking for anyone to complete my program for me, but rather point out what I can include to make it suit what I'm looking for. Any additional help on how what is wrong in my program would be very very appreciated. Again, I know that I need to know how to do this to pass my class so all I ask is guidance. Thank you so much!

    Code:
    #include <iostream>
    #include <cmath>
    using namespace std;
    int main()
    {
    //Declare and initialize variables and constants
    //p = Pressure (kPa), V = Volume (m^3), m = mass (kg), R = Gas Constant (0.0281), T = Temperature (C) and (K)
    //MM = other molar mass
    
    
    int p, V, m, R, T, K, MM, code ;
    R = 0.287 ;
    K = T + 273.15 ;
    //**Print**//
    //Introduction
    cout << "Welcome to the My Ideal Gas Law Solver! \n" <<endl;
    cout << "This program solves p*V=m*R*T for p, V or T given" <<endl;
    cout << "the other two along with mass and the type of gas. \n" <<endl;
    cout << "Select a gas by entering the corresponding number:" <<endl;
    cout << "(1) Steam M = 18.02" <<endl;
    cout << "(2) Nitrogen M = 28.01" <<endl;
    cout << "(3) Air M = 28.97" <<endl;
    cout << "(4) Oxygen M = 32.00" <<endl;
    cout << "(5) Carbon Dioxide M = 44.01" <<endl;
    cout << "(6) Other \n" <<endl;
    //User inputs
    switch (code)
    {
    case 1:
    cout << "You have chosen Steam." <<endl;
    break;
    case 2:
    cout << "You have chosen Nitrogen." <<endl;
    break;
    case 3:
    cout << "You have chosen Air." <<endl;
    break;
    case 4:
    cout << "You have chosen Oxygen." <<endl;
    break;
    case 5:
    cout << "You have chosen Carbon Dioxide." <<endl;
    break;
    case 6:
    cout << "Please enter a Molar Mass for the gas you wish to calculate in kg:" <<endl;
    break;
    default:
    cout << "Error with selection. Please pick a number between 1 and 6 next time." <<endl;
    break;
    }
    
    
    int input = 0;
    while (((input<1 || input>5) && input!=6))
    { cout << "Please enter an integer between 1 and 6: ";
      cin >> input;
    }
    
    
    if (code == 6)
    {
        cin >> MM ;
    cout << "You have chosen " << MM <<endl;
    }
    
    
    cout << "Select a variable to solve for by entering the corresponding number: " <<endl;
    cout << "(1) Pressure" <<endl;
    cout << "(2) Volume" <<endl;
    cout << "(3) Temperature" <<endl;
    cin >> code;
    switch (code)
    {
    case 1:
    cout << "Please enter the volume in cubic meters: " <<endl;
    cin >> V;
    cout << "Please enter the temperature in degrees celsius: " <<endl;
    cin >> T;
    break;
    case 2:
    cout << "Please enter the pressure in kiloPascals: " <<endl;
    cin >> p;
    cout << "Please enter the temperature in degrees celsius: " <<endl;
    cin >> T;
    break;
    case 3:
    cout << "Please enter the pressure in kiloPascals: " <<endl;
    cin >> p;
    cout << "Please enter the volume in cubic meters: " <<endl;
    cin >> V;
    break;
    
    
    //Compute Ideal Gas Law equation
    if (code == 1)
    {
        p = (m * R * T)/V ;
    }
    if (code == 2)
    {
        V = (m * R * T)/p ;
    }
    if (code == 3)
    {
        T = (p * V)/(m * R) ;
    }
    
    
    //Compute Temperature conversion
    cout << "Ideal Gas Law computation results:" << endl;
    cout << "Gas name: " << endl;
    cout << "Unknown value: " << endl;
    cout << "Molar weight: " << endl;
    cout << "Gas constant: " << R << " kJ/kg-K" << endl;
    cout << "Mass: " << endl;
    cout << "Pressure: " << p << " kPa" << endl;
    cout << "Temperature: " << T << " C" << endl;
    cout << "Volume: " << V << " m^3" << endl;
    return 0;
    }
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I do NOT see the problem you tried to describe; but, where is the value of "code" set in your program?

    Edit1: It is strongly suggested to NOT use variables before that are set to known values for beginners and even most experts (if NOT all).

    I suggest indenting your program if you want help.

    Edit2: Use variables names that you can remember what they mean; that seems to likely be the root cause of your program issues.

    Edit3: Turn up your compiler warnings and read the warnings; if you get no warning get a better compiler!

    Tim S.
    Last edited by stahta01; 02-07-2014 at 10:55 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Feb 2014
    Posts
    18
    In lines 60-64 the if code is meant to redirect the user to an option where they input their own molar mass. Otherwise, options 1-5 on lines 27-50 with the preset molar masses are meant to directly take the user to the variable selection screen (i.e. volume, pressure, temperature). I'm sorry, I should have elaborated my question a little better.

  4. #4
    Registered User
    Join Date
    Feb 2014
    Posts
    18
    I've been working on this program some more and have this:

    Code:
    #include <iostream>
    #include <cmath>
    using namespace std;
    int main()
    {
    //Declare and initialize variables and constants
    //p = Pressure (kPa), V = Volume (m^3), m = mass (kg), R = Gas Constant (0.0281), T = Temperature (C) and (K)
    //MM = other molar mass
    int p, V, m, R, T, K, MM, code;
    //**Print**//
    //Introduction
    cout << "Welcome to the My Ideal Gas Law Solver! \n" <<endl;
    cout << "This program solves p*V=m*R*T for p, V or T given" <<endl;
    cout << "the other two along with mass and the type of gas. \n" <<endl;
    cout << "Select a gas by entering the corresponding number:" <<endl;
    cout << "(1) Steam M = 18.02" <<endl;
    cout << "(2) Nitrogen M = 28.01" <<endl;
    cout << "(3) Air M = 28.97" <<endl;
    cout << "(4) Oxygen M = 32.00" <<endl;
    cout << "(5) Carbon Dioxide M = 44.01" <<endl;
    cout << "(6) Other \n" <<endl;
    //User inputs
    int input = 0;
    while (input<1 || (input>5 && input!=6))
    { cout << "Please enter a number between 1 and 6: ";
      cin >> input;
      code = input;
    }
    switch (code)
    {
    case 1:
    cout << "You have chosen Steam." <<endl;
    m=18.02;
    break;
    case 2:
    cout << "You have chosen Nitrogen." <<endl;
    m=28.01;
    break;
    case 3:
    cout << "You have chosen Air." <<endl;
    m=28.97;
    break;
    case 4:
    cout << "You have chosen Oxygen." <<endl;
    m=32.00;
    break;
    case 5:
    cout << "You have chosen Carbon Dioxide." <<endl;
    m=44.01;
    break;
    case 6:
    cout << "Please enter a Molar Mass for the gas you wish to calculate in kg:" <<endl;
    cin>>MM;
    cout << "You have chosen " << MM <<endl;
    m=MM;
    break;
    }
    cout << "Select a variable to solve for by entering the corresponding number: " <<endl;
    cout << "(1) Pressure" <<endl;
    cout << "(2) Volume" <<endl;
    cout << "(3) Temperature" <<endl;
    cin >> code;
    switch (code)
    {
    case 1:
    cout << "Please enter the volume in cubic meters: " <<endl;
    cin >> V;
    cout << "Please enter the temperature in degrees celsius: \n" <<endl;
    cin >> T;
    break;
    case 2:
    cout << "Please enter the pressure in kiloPascals: " <<endl;
    cin >> p;
    cout << "Please enter the temperature in degrees celsius: \n" <<endl;
    cin >> T;
    break;
    case 3:
    cout << "Please enter the pressure in kiloPascals: " <<endl;
    cin >> p;
    cout << "Please enter the volume in cubic meters: \n" <<endl;
    cin >> V;
    break;}
    //Compute Ideal Gas Law equation
    R = 0.287 ;
    K = T + 273.15 ;
    if (code == 1)
    {
        p = (m * R * K)/V ;
    }
    if (code == 2)
    {
        V = (m * R * K)/p ;
    }
    if (code == 3)
    {
        K = (p * V)/(m * R) ;
    }
    //Compute Temperature conversion
    cout << "Ideal Gas Law computation results!" << endl;
    cout << "Gas name: " << endl;
    cout << "Unknown value: " << endl;
    cout << "Molar weight: " << endl;
    cout << "Gas constant: " << R << " kJ/kg-K" << endl;
    cout << "Mass: " << endl;
    cout << "Pressure: " << p << " kPa" << endl;
    cout << "Temperature: " << T << " C" << endl;
    cout << "Volume: " << V << " m^3" << endl;
    return 0;
    }

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You should indent your code properly to make it more readable.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Feb 2014
    Posts
    18
    It somehow keeps getting messed up every time I paste it here. I've got the indents in my program.

  7. #7
    Registered User
    Join Date
    Feb 2014
    Posts
    18
    does this help some?

    Code:
    #include <iostream>
    #include <cmath>
    using namespace std;
    int main()
    
    
    {
    //Declare and initialize variables and constants
    //p = Pressure (kPa), V = Volume (m^3), m = mass (kg), R = Gas Constant (0.0281), T = Temperature (C) and (K)
    //MM = other molar mass
    
    
    int p, V, m, R, T, K, MM, code;
    
    
    //**Print**//
    
    
    //Introduction
        cout << "Welcome to the My Ideal Gas Law Solver! \n" <<endl;
        cout << "This program solves p*V=m*R*T for p, V or T given" <<endl;
        cout << "the other two along with mass and the type of gas. \n" <<endl;
        cout << "Select a gas by entering the corresponding number:" <<endl;
        cout << "(1) Steam M = 18.02" <<endl;
        cout << "(2) Nitrogen M = 28.01" <<endl;
        cout << "(3) Air M = 28.97" <<endl;
        cout << "(4) Oxygen M = 32.00" <<endl;
        cout << "(5) Carbon Dioxide M = 44.01" <<endl;
        cout << "(6) Other \n" <<endl;
    //User inputs
    int input = 0;
    while (input<1 || (input>5 && input!=6))
    { cout << "Please enter a number between 1 and 6: ";
      cin >> input;
      code = input;
    }
    switch (code)
    {
        case 1:
            cout << "You have chosen Steam." <<endl;
        m=18.02;
            break;
        case 2:
            cout << "You have chosen Nitrogen." <<endl;
        m=28.01;
            break;
        case 3:
            cout << "You have chosen Air." <<endl;
        m=28.97;
            break;
        case 4:
            cout << "You have chosen Oxygen." <<endl;
        m=32.00;
            break;
        case 5:
            cout << "You have chosen Carbon Dioxide." <<endl;
        m=44.01;
            break;
        case 6:
            cout << "Please enter a Molar Mass for the gas you wish to calculate in kg:" <<endl;
            cin >> MM;
            cout << "You have chosen " << MM <<endl;
            m=MM;
            break;
    }
    
    
        cout << "Select a variable to solve for by entering the corresponding number: " <<endl;
        cout << "(1) Pressure" <<endl;
        cout << "(2) Volume" <<endl;
        cout << "(3) Temperature" <<endl;
        cin >> code;
        switch (code)
    {
        case 1:
            cout << "Please enter the volume in cubic meters: " <<endl;
            cin >> V;
            cout << "Please enter the temperature in degrees celsius: \n" <<endl;
            cin >> T;
        break;
        case 2:
            cout << "Please enter the pressure in kiloPascals: " <<endl;
            cin >> p;
            cout << "Please enter the temperature in degrees celsius: \n" <<endl;
            cin >> T;
        break;
        case 3:
            cout << "Please enter the pressure in kiloPascals: " <<endl;
            cin >> p;
            cout << "Please enter the volume in cubic meters: \n" <<endl;
            cin >> V;
        break;}
    //Compute Ideal Gas Law equation
        R = 0.287 ;
    
    
        K = T + 273.15 ;
    
    
    if (code == 1)
    {
        p = (m * R * K)/V ;
    }
    if (code == 2)
    {
        V = (m * R * K)/p ;
    }
    if (code == 3)
    {
        K = (p * V)/(m * R);
        T = K - 273.15;
    }
    //Compute Temperature conversion
        cout << "Ideal Gas Law computation results!" << endl;
        cout << "Gas name: " << endl;
        cout << "Unknown value: " << endl;
        cout << "Molar weight: " << endl;
        cout << "Gas constant: " << R << " kJ/kg-K" << endl;
        cout << "Mass: " << endl;
        cout << "Pressure: " << p << " kPa" << endl;
        cout << "Temperature: " << T << " C" << endl;
        cout << "Volume: " << V << " m^3" << endl;
        return 0;
    }

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Allen Sarkisov View Post
    In lines 60-64 the if code is meant to redirect the user to an option where they input their own molar mass.
    Maybe so. But none of the code before line 60 (which is executed before line 60) sets the variable code to have a value.

    Quote Originally Posted by Allen Sarkisov View Post
    Otherwise, options 1-5 on lines 27-50 with the preset molar masses are meant to directly take the user to the variable selection screen (i.e. volume, pressure, temperature). I'm sorry, I should have elaborated my question a little better.
    You need to think a bit more sequentially. Statements in C++ are executed (within a given scope, such as a function or a block within a function) in the order they are written - from top down.

    So the switch statement on line 27 is executed and completed BEFORE the if() statement on line 60. They are not alternatives to each other.

    EDIT: the line numbers I'm referring to are in your original post, not your first. I also read this thread sequentially.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    For some reason, all of the variables in your program are integers, but you want to use floating point math.
    After all, you can't properly convert to kelvin without adding 273.15!

    So either you are entering in decimals anyway and ignoring the type of your variables, which will make your cin statements break, or you really are entering in whole numbers and then your calculations break because all of the nice floating point constants you use get implicitly converted to integers. You really ought to use double for any variables involved in calculations, and this does NOT mean that you go to the 1 line that has all of your variables declared and change int to double! It's an extremely bad habit to declare variables that way.

    For 1) C++ variable types can often have multiple parts separated by whitespace (such as &, *, < and >) that only lead to type related errors if you aren't careful.
    For 2) it's messy.
    For 3) you seem to think that there is a magic type that all of your variables can be, and this is not true -- programs can depend on hundreds of types -- so declaring everything on one big line is not plausible.

  10. #10
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Hundreds of types... and people wonder why I dislike C++. But types aren't really the problem. The problem, in my opinion, is that C++ doesn't know what it is. The other problem is that the definition of "good C++" practices changes every couple of weeks. After that the standard changes. The standard libraries change as well. C++ was good about 10 years ago. Today, it's a bit of a joke. I have an idea: someone should suggest adding Cairo to the standard.
    Last edited by Hodor; 02-08-2014 at 06:22 AM.

  11. #11
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    If this was spurred by my comment that it's bad to write all your declarations on one line, then I'm rather shocked you disagree. The reasoning in my post stands in spite of any argument you have yet to give. I don't want to see the OP try this:
    Code:
    double p, V, m, R, T, K, MM, code;
    Because he would, probably, and that just causes more problems.

    Hundreds of types... and people wonder why I dislike C++.
    It's not unique to C++ at all, though.

    But types aren't really the problem.
    They are, they really are, in the context of the OP's code.

    The problem, in my opinion, is that C++ doesn't know what it is. The other problem is that the definition of "good C++" practices changes every couple of weeks. After that the standard changes. The standard libraries change as well. C++ was good about 10 years ago. Today, it's a bit of a joke. I have an idea: someone should suggest adding Cairo to the standard.
    In general, you are complaining about the speed at which C++'s standard changes. Stop me if I am wrong. I don't really care enough to agree or disagree, but I definitely have to go with the flow. We still live in a world where Moore's law is unbroken, and I feel like software development will only continue to change at a similar speed. I don't like it, but I don't have a choice.

    "Conventions" and canonical code can only take you so far anyway, you will reach a point where you are slightly out of date, your code still works, and precisely no one cares. Don't be too sensitive, I guess, is the take away moral.
    Last edited by whiteflags; 02-08-2014 at 06:38 AM.

  12. #12
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by whiteflags View Post
    It's not unique to C++ at all, though.
    I edited my post before you replied (sorry). I think however it is unique to C++... it's a moving target that nobody in their right mind can possibly hope to keep up with. Or, for that matter, want to keep up with.

  13. #13
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I think however it is unique to C++... it's a moving target that nobody in their right mind can possibly hope to keep up with.
    O_o

    I'm not naming names, but I know at least one person who hasn't tried to stay current with Ada, C#, Javascript, PHP, or Python over the last decade.

    I'm not trying to post an exhaustive list or anything; those are just languages I know have made braking changes in the last 10 years.

    Besides, growth is a good thing; these languages and others admitting their many, many flaws over time vastly improves the quality of programming languages. (The things Javascript and Python keep borrowing from each other and LISP may soon make Javascript really great and see me abandoning C++ for Python.) If these languages hadn't changed at all in a decade, most people would not want to use them; at some point, switching to a language that has admitted and attempted to fix mistakes is fa easier than patching over all the sins and syntax.

    [Edit]
    Certainly, marking breaking changes to evolve isn't limited to C++; the best parts of the newest Javascript technical recommendations comes riding over the corpse of awful problems with the current standard.
    [/Edit]

    Soma
    Last edited by phantomotap; 02-08-2014 at 06:47 AM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Hodor View Post
    Hundreds of types... and people wonder why I dislike C++.
    Lots of types are a good thing. This allows us to express stricter invariants which results in less testing.
    Compare to Javascript which is horrible because it has no sense of types. It's not even compiled.
    How much time do you have to spend on testing the damn code to see if it's actually right instead of having the compiler telling you it's wrong?
    Types are a good thing™, but you usually don't realize this until you start coding in typeless languages.

    But types aren't really the problem. The problem, in my opinion, is that C++ doesn't know what it is.
    Why would you say that? Are you finding that there isn't enough focus somewhere?

    The other problem is that the definition of "good C++" practices changes every couple of weeks. After that the standard changes.
    No one is perfect. Languages aren't perfect either, regardless of how much we try to make them perfect when they're first released.
    People are bound to find better ways to do things and people keep finding problems with designs. It's a learning process and it happens to every language.

    The standard libraries change as well. C++ was good about 10 years ago. Today, it's a bit of a joke. I have an idea: someone should suggest adding Cairo to the standard.
    Why are today's libraries a joke? Because they lack functionality? Something else?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    Feb 2014
    Posts
    18
    Thank you so much guys on the suggestions! It's slowly morphing more and more into what I am looking for. Is this what you guys meant about changing the variable so they're not only integers?

    Code:
    #include <iostream>
    #include <cmath>
    using namespace std;
    int main()
    {
    //Declare and initialize variables and constants
    //p = Pressure (kPa), V = Volume (m^3), m = mass (kg), R = Gas Constant (0.0281), T = Temperature (C) and (K)
    //MM = other molar mass
    float p, V, m, R, T, K, MM;
    int code;
    std::string gN;
    //**Print**//
    //Introduction
        cout << "Welcome to the My Ideal Gas Law Solver! \n" <<endl;
        cout << "This program solves p*V=m*R*T for p, V or T given" <<endl;
        cout << "the other two along with mass and the type of gas. \n" <<endl;
        cout << "Select a gas by entering the corresponding number:" <<endl;
        cout << "(1) Steam M = 18.02" <<endl;
        cout << "(2) Nitrogen M = 28.01" <<endl;
        cout << "(3) Air M = 28.97" <<endl;
        cout << "(4) Oxygen M = 32.00" <<endl;
        cout << "(5) Carbon Dioxide M = 44.01" <<endl;
        cout << "(6) Other \n" <<endl;
    //User inputs
    int input = 0;
    while (input<1 || (input>5 && input!=6))
    { cout << "Please enter a number between 1 and 6: ";
      cin >> input;
      code = input;
    }
    switch (code)
    {
        case 1:
            cout << "You have chosen Steam." <<endl;
        m=18.02;
        gN="Steam";
        R=8.314;
            break;
        case 2:
            cout << "You have chosen Nitrogen." <<endl;
        m=28.01;
        gN="Nitrogen";
        R=8.314;
            break;
        case 3:
            cout << "You have chosen Air." <<endl;
        m=28.97;
        gN="Air";
        R=0.287;
            break;
        case 4:
            cout << "You have chosen Oxygen." <<endl;
        m=32.00;
        gN="Oxygen";
        R=8.314;
            break;
        case 5:
            cout << "You have chosen Carbon Dioxide." <<endl;
        m=44.01;
        gN="Dioxide";
        R=8.314;
            break;
        case 6:
        cout << "Please enter the name of the Gas you are calculating:"<<endl;
        cin >> gN;
        cout << "You have chosen the name" << gN << endl;
        cout << "Please enter a Molar Mass for the gas you wish to calculate in kg:" <<endl;
        cin >> MM;
        cout << "You have chosen " << MM <<endl;
        m=MM;
        R=8.314;
            break;
    }
        cout << "Select a variable to solve for by entering the corresponding number: " <<endl;
        cout << "(1) Pressure" <<endl;
        cout << "(2) Volume" <<endl;
        cout << "(3) Temperature" <<endl;
        cin >> code;
    switch (code)
    {
        case 1:
            cout << "Please enter the volume in cubic meters: " <<endl;
            cin >> V;
            cout << "Please enter the temperature in degrees celsius: \n" <<endl;
            cin >> T;
        break;
        case 2:
            cout << "Please enter the pressure in kiloPascals: " <<endl;
            cin >> p;
            cout << "Please enter the temperature in degrees celsius: \n" <<endl;
            cin >> T;
        break;
        case 3:
            cout << "Please enter the pressure in kiloPascals: " <<endl;
            cin >> p;
            cout << "Please enter the volume in cubic meters: \n" <<endl;
            cin >> V;
        break;}
    //Compute Ideal Gas Law equation
    K = T + 273.15 ;
    //pV = m(8.314/M)T
    if (code == 1)
    {
        p = (m * R * K)/V ;
    }
    else if (code == 2)
    {
    
    
        V = (m * R * K)/p ;
    }
    else if (code == 3)
    {
        K = (p * V)/(m * R) ;
    }
    //Compute Temperature conversion
        cout << "Ideal Gas Law computation results:" << endl;
        cout << "Gas name: " << gN << endl;
        cout << "Molar weight: " << endl;
        cout << "Mass: " << endl;
        cout << "Pressure: " << p << " kPa" << endl;
        cout << "Temperature: " << T << " C" << endl;
        cout << "Volume: " << V << "m^3" << endl;
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switch Statements
    By lazyturtle in forum C++ Programming
    Replies: 12
    Last Post: 05-02-2007, 02:40 AM
  2. Switch statements ...
    By twomers in forum C Programming
    Replies: 2
    Last Post: 01-06-2006, 07:14 AM
  3. switch statements
    By joshua in forum C Programming
    Replies: 3
    Last Post: 11-21-2005, 03:26 AM
  4. Need help with if /else statements - maybe switch
    By dwinslett in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2003, 07:23 AM
  5. Switch Statements.
    By RealityFusion in forum C++ Programming
    Replies: 16
    Last Post: 08-19-2003, 11:55 PM

Tags for this Thread