C++ Programming

Discussion in 'Computer Programming, Emulation, and Game Modding' started by jDSX, Oct 27, 2015.

  1. jDSX
    OP

    jDSX *pokes*

    Member
    917
    1,417
    Jun 15, 2015
    United States
    Happy furry land with Lucar
    Could somebody please help me with this I am struggling to get it done [​IMG]
    This (http://puu.sh/kJEoV/7aa0bcb15d.png) is what I have so far and I do not know what I am suppose to do next. Assignment will be due soon, would really appreciate it!
     
  2. DiscostewSM

    DiscostewSM GBAtemp Guru

    Member
    5,009
    2,641
    Feb 10, 2009
    United States
    Sacramento, California
    Which part? This is just a program using the selection structures of "if" and "if-else" statements, yes? Do you need help with how to put those together, or how to check for errors, or something else?
     
  3. jDSX
    OP

    jDSX *pokes*

    Member
    917
    1,417
    Jun 15, 2015
    United States
    Happy furry land with Lucar
    Tried to solve the first one but I have no idea if I did it right
    code
     
  4. barronwaffles

    barronwaffles GBAtemp Regular

    Member
    212
    227
    May 15, 2014
    Syria
    I weep for the future.
     
  5. jDSX
    OP

    jDSX *pokes*

    Member
    917
    1,417
    Jun 15, 2015
    United States
    Happy furry land with Lucar
    Putting them together
     
  6. Jhyrachy

    Jhyrachy GBAtemp Regular

    Member
    213
    71
    Jul 25, 2011
    Italy
    I like the 5 #include without the library to include
     
    TheKawaiiDesu and Monado_III like this.
  7. jDSX
    OP

    jDSX *pokes*

    Member
    917
    1,417
    Jun 15, 2015
    United States
    Happy furry land with Lucar
    Not sure why that shows up like that it should be < and >
     
  8. spoonm

    spoonm Can count to 3.

    Member
    174
    84
    May 20, 2015
    Brazil
    This.

    Indeed, you should include libraries(more specifically, header files), like iostream.

    I don't get why you're separating blocks of code for no apparent reason in your main function. You also don't seem to keep consistency in your programming style. Here's what you're doing:

    Code:
    ...
    if (hrz>21)
    {
        cout<<"You are exceeding 21 semester hours"<<endl;
    }
    else if(hrz<12)
        cout<<"You are taking less than 12 semester hours"<<endl;
    ...
    { // Why are you starting a new block?
    if (room == 'R')
        cout<<"Room Type : Regular : "<<regroom<<endl;
    else if (room == 'A')
        cout<<"Room Type : Air-Conditioned : "<<acroom<<endl;
    }
    
    I think when you copy-pasted your code, you lost all whitespace, hence the lack of indentation and other spaces.

    Remember to keep your code readable. Comment it, but do so in an organized fashion.

    About the assignment:

    If you're going to compare a variable with multiple constants(looking at room, here), you're better off using the switch command. Here's an example of how to use it:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void)
    {
        char pew;    // pew pew space lasers.
    
        cout << "Hey, type a letter:";
        cin >> pew;
    
        switch (pew)
        {
            case 'A':
                for (int i = 0; i < 10; i++)
                    cout << pew++;
                cout << endl;
                break;    // Needed to get out of the switch structure.
    
            case 'B':    // Will continue to do what case 'C' does.
            case 'C':
                cout << "You typed either B or C. Now which one was it..." << endl;
                break;    // Outta here!
            ...
            default:
                cout << "I couldn't predict your movements!" << endl;
        }
    
        return 0;
    }
    You can find more convenient and useful ways to use it, but I guess that can help you understand the syntax.

    EDIT: An observation to make: if you're using an IDE, its editor is likely going to indent the cases the same as your switch statement, regardless of you starting a new block of code. That is to do with the fact they're labels, not actual blocks of code, which will go indented. It's personal preference, however, I indent my cases when I do use switch.
     
    Last edited by spoonm, Nov 5, 2015