Program keeps giving me different answers
Whenever I type in 1994 and M it will give me one answer then I do it again and its different
#include <iostream> using namespace std; int main () { int yr; char gender; int yrd; yrd = ( 2012 ) - yr ; cout << "Enter your year of birth:" << endl; cin >> yr ; cout << "Enter your Gender(M/F):" << endl; cin >> gender ; if ( ( gender == 'M') && yr <= 2012) cout << "You will die in " <<(75 - yrd ) * (365 * 24 *60 *60) << "seconds" << endl; else if (( gender == 'F') && yr <= 2012) cout << "You will die in " << (80 - yrd ) * ( 365 * 24 * 60 *60) <<" seconds" << endl; else cout << "Your input was invalid you idiot. Run the program again!" << endl; return 0; } |
Your problem is you are doing the yrd calculation before the user enters his input.
Code:
|
Use [CODE][/CODE] tags around your code to make it more legible.
The problem is here: Code:
//... EDIT: oops, beaten by crabboy... Sorry :D |
it still comes out with random answers, where should I move it?
|
Quote:
I assume you changed something based on the earlier answers you got. But I don't know what you changed. Also, did you remember to recompile the program after changing the source code? Maybe you are still running the earlier version. |
All times are GMT -5. The time now is 07:36 AM. |