Program isn't calculating totals correctly?
Sep 14, 2013 at 10:35pm UTC
Hello, for my CSC100AB class, we are writing programs that calculate the total tuition given different variables. I compiled the program with no errors, but the total tuition calculations are all wrong. Thank you for any help!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#include <iostream>
#include <iomanip>
using namespace std;
void main ()
{
//CONSTANTS
const double major_c = 25;
const double major_o = 35;
const double major_a = 0;
const double registration_fee = 15;
const double in_state = 0;
const double out_state = 0.20;
const double full_time = 950;
const double credit_rate = 95;
//INPUT VARIABLES
double credit_hours;
char living_status;
char major_code;
//CALCULATION VARIABLES
double credit_hr_charge;
double lab_fee;
double living_fee;
//OUTPUT VARIABLE
double tuition_total;
cout << "Enter credit hours: " ;
cin >> credit_hours;
cout << "Enter major ('C' - Computer Science, 'O' - Other Lab Sciences or 'A' for any other major):" ;
cin >> major_code;
cout << "Enter living status ('1' - In-state or '2' - Out of State)" ;
cin >> living_status;
if ( credit_hours < 12)
{
credit_hr_charge = credit_hours * credit_rate;
}
else
{
credit_hr_charge = full_time;
}
if (major_code == 'C' || major_code == 'c' )
{
lab_fee = major_c;
}
else if (major_code == 'O' || major_code == 'o' )
{
lab_fee = major_o;
}
else
{
lab_fee = major_a;
}
if (living_status == '2' )
{
living_fee = out_state;
}
else
{
living_fee = in_state;
}
//CALCULATIONS
tuition_total = credit_hr_charge * living_fee + lab_fee + registration_fee;
cout<< "Total Tuition Cost: $" << tuition_total;
system ( "pause" );
}
Sep 14, 2013 at 10:53pm UTC
Did you really intend to multiply credit_hr_charge by living_fee?
Sep 14, 2013 at 11:01pm UTC
Students are charged 20% of the base tuition price if they live out of state... I changed it to:
//CALCULATIONS
o_charge = credit_hr_charge * living_fee
tuition_total = credit_hr_charge + o_charge + lab_fee + registration_fee;
cout<< "Total Tuition Cost: $" << tuition_total;
system ( "pause" );
}
but the calculations are still wrong..
Topic archived. No new replies allowed.