C++ Programming

jDSX

Well-Known Member
OP
Member
Joined
Jun 15, 2015
Messages
1,202
Trophies
1
Age
32
Location
Lost woods
XP
1,639
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
32
Location
Lost woods
XP
1,639
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
299
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,
General chit-chat
Help Users
  • JuanMena @ JuanMena:
    Kissing random dudes choking in celery? Really? Need to study for that?
  • K3N1 @ K3N1:
    Yes it requires a degree
  • K3N1 @ K3N1:
    I could also yank out the rest of my teeth but theirs professionals for that
  • x65943 @ x65943:
    If your throat closes, putting oxygen in your mouth will not solve anything - as you will be introducing oxygen prior to the area of obstruction
  • JuanMena @ JuanMena:
    Just kiss me Kyle.
  • x65943 @ x65943:
    You either need to be intubated to bypass obstruction or create a stoma inferior to the the area of obstruction to survive
  • x65943 @ x65943:
    "Just kiss me Kyle." And I thought all the godreborn gay stuff was a smear campaign
  • JuanMena @ JuanMena:
    If I die, tell my momma I won't be carrying Baby Jesus this christmas :sad::cry:
  • K3N1 @ K3N1:
    Smear campaigns are in The political section now?
  • JuanMena @ JuanMena:
    Chary! Chary! Chary, Chary, Chary!
  • Sonic Angel Knight @ Sonic Angel Knight:
    Pork Provolone :P
  • Psionic Roshambo @ Psionic Roshambo:
    Sounds yummy
  • K3N1 @ K3N1:
    Sweet found my Wii u PSU right after I ordered a new one :tpi:
  • JuanMena @ JuanMena:
    It was waiting for you to order another one.
    Seems like, your PSU was waiting for a partner.
  • JuanMena @ JuanMena:
    Keep them both
    separated or you'll have more PSUs each year.
  • K3N1 @ K3N1:
    Well one you insert one PSU into the other one you get power
  • JuanMena @ JuanMena:
    It literally turns it on.
  • K3N1 @ K3N1:
    Yeah power supplies are filthy perverts
  • K3N1 @ K3N1:
    @Psionic Roshambo has a new friend
    +1
  • JuanMena @ JuanMena:
    It's Kyle, the guy that went to school to be a Certified man Kisser.
  • Psionic Roshambo @ Psionic Roshambo:
    Cartmans hand has taco flavored kisses
  • A @ abraarukuk:
    hi guys
  • Iron_Masuku @ Iron_Masuku:
    Hello
    Skelletonike @ Skelletonike: hmm