C++ Programming

jDSX

Well-Known Member
OP
Member
Joined
Jun 15, 2015
Messages
1,202
Trophies
1
Age
33
Location
Lost woods
XP
1,696
Country
United States
Could somebody please help me with this I am struggling to get it done
635402ace10f251f5b43463d74cea1dc.png

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!
 

jDSX

Well-Known Member
OP
Member
Joined
Jun 15, 2015
Messages
1,202
Trophies
1
Age
33
Location
Lost woods
XP
1,696
Country
United States
Tried to solve the first one but I have no idea if I did it right
#include
#include
#include
#include
#include
using namespace std;
int main()
{
double matric = 30;//matriculation fee
int hrz;//semester hours
char room;//room option
double regroom = 200;//rate for regular room
double acroom = 250;//rate for AC room
double dip = 35;//diploma fee
char grad;//graduation option
double food = 400;//rate for food
int stunum;//student ID #
double credit = 90;//cost of each semester hour

cout<<"Please enter the student #"<<endl;
cin>>stunum;

cout<<"What are the number of semester hours?"<<endl;
cin>>hrz;

cout<<"Please enter your Room Choice: (R/A)"<<endl;
cin>>room;

cout<<"Is the student graduating?: (Y/N)"<<endl;
cin>>grad;

cout<<stunum<<endl;
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;
double totalfeez = credit * hrz;//total fee for individual student
cout<<"Tuition: "<<totalfeez<<endl;
{
if (room == 'R')
cout<<"Room Type : Regular : "<<regroom<<endl;
else if (room == 'A')
cout<<"Room Type : Air-Conditioned : "<<acroom<<endl;
}
cout<<"Food : "<<food<<endl;
cout<<"Matriculation : "<<matric<<endl;
{
if (grad == 'Y')
cout<<"Diploma fee : "<<dip<<endl;
else if (grad == 'N')
cout<<"No graduation this semester"<<endl;
}
double totalcost = totalfeez + dip + matric + room + food;
cout<<"Total Fees : "<<totalcost<<endl;
return 0;
}
 

spoonm

Can count to 3.
Member
Joined
May 20, 2015
Messages
192
Trophies
0
Website
spoonm.org
XP
317
Country
Brazil
I weep for the future.

This.

Not sure why that shows up like that it should be < and >

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,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: They really wanna get the head