HELP! what have i done wrong?!

PLEASE PLEASE PLEASE HELP ME!!! i have no idea what i'm doing wrong. Below are the instructions for my school assignment as well as my code so far. whenever I input the numbers 5, 4, 0, 160 I'm getting in the 600 range when it should be in the 100 range. please tell me what i'm doing wrong and give me any tips. I know its very basic but i have pretty much no experience with programming

Marge Simpson has unique hair. You cannot argue this; don't even try. The height of her 'do actually fluctuates from day to day. It's hard to notice that since you are focusing on just how stupid all the Simpsons characters are acting. But I digress. There is a way to calculate this height, and, in fact, Marge uses this formulation every day as she preps and primps in the morning. She would like you to code a program she can use to quickly compute hair height (forthwith1 known as "hh") to simplify her life.

Specifications: You are to write a program that will prompt for and input from the user (presumably Marge) values for

the number of days since her last cut: days
the number of cans of hairspray used that morning: cans
whether or not mousse is used that morning2: mousse3
the temperature of the curling iron: temp

Now, it should be clear what the types of these inputs should be. But if it's not, know now that

days should be an integer-type
cans should also be an integer type since Marge never leaves a can partially used - that would be sacrilege.
mousse is a bool, especially if you read the footnote!
temp is a float-type

There are also values that play a part in the computations that are not inputs from the user, but are very important nonetheless. They are:

the rate at which Marge's hair grows. This RATE is currently known to be 0.2
the acceleration of gravity. G = 9.98. (You know, gravity is always pulling that tower of hair down!)

Marge, through extensive scientific studies performed by the eminent scientist, Dr. Frink, has determined that the hh value is given by the following formulation:

hh = (cans/(days + 1)) * (2 + temp) - G + <<RTD>>,

where <<RTD>> signifies that RTD is added in only if mousse is used that day. RTD is rate * days.

Your program should be "user friendly" in that it should have an opening statement or greeting, user friendly and understandable prompts, and clear and concise outputs and sign-off. Here's a good example of bad output:

enter stuff: 5 4 0 160

Notice that there are NO prompts to speak of, and the output is completely unexplained. This is horrible output. Something like the following is much much better:

Greetings ......
Please enter the following:
days since last cut: 5
cans of spray used: 4
mousse (1/0): 0
curler temp: 160

You hair height will be 98.0189 inches.

Have a nice day, Marge!!

Notice how everything is very clear? (Yes)

When you submit: When you submit this, and all subsequent programs for this class, cssubmit will compile and run (assuming it compiles) your program during the submission process. Thus, when you submit, you will have to enter inputs as a user of the program. Now, in order to make the output uniform for the grader and to keep her sane, ALL OF YOU will enter the same information. For this assignment, it is:

days: 28
cans: 4
mousse: has been used
temperature: 200

Special Notice: You are NOT to use the if-else statement....or even the if statement! in this assignment. Think carefully about your inputs and how they can be used.

This is my code that i've written so far
using namespace std;

//constant declaration
const float G = 9.98;
const float RATE = .2;

int main ()
//variable declaration
int days;
int cans;
bool mousse = 1;
float temp;
float hh;
float RTD;

//greet user and prompt for entry
cout << "good morning, Marge!" << endl;
cout << "please enter the following information:" << endl;
cout << "days since last cut:" << endl;
cin >> days;
cout << "cans of hair spray used:" << endl;
cin >> cans;
cout << "if mousse was used (1/0):" << endl;
cin >> mousse;
cout << "curler temp:" << endl;
cin >> temp;

//calculates hh
RTD = RATE * days;
hh = (cans % (days + 1)) * (2 + temp) - G + (RTD == mousse);

//results calculated
cout << "Your hair height is: " << hh << endl;
cout << "have a great day!" << endl;
return 0;
> i have no idea what i'm doing wrong.

In hh = (cans % (days + 1)) * (2 + temp) - G + (RTD == mousse);

a. Change the % (modulo or integer remainder) operator to / (division)
b. And the division that we want is not integer division

Change to: hh = ( cans / ( days + 1.0 ) ) * (2 + temp) - G + (RTD == mousse);
Thank you.
I've changed my code to this
hh= (cans / (days + 1.0)) * (2 + temp) - G + (mousse == 1 ? RTD:0)

whenever i put in a value where the number of cans is smaller that the number of days (plus 1) it changes the value of that division to zero which messes up my entire equation.
how do i fix this?
> whenever i put in a value where the number of cans is smaller that the number of days (plus 1)
> it changes the value of that division to zero

No, it won't.

#include <iostream>

int main()
    int cans = 7 ;
    int days = 12 ;
    std::cout << cans / ( days + 1.0 ) << '\n' ; // 0.538462
    std::cout << cans / ( days + 1 ) << '\n' ; // 0 (integer division)
Topic archived. No new replies allowed.