If I take out the cin (along with the digits variable) it will build and run fine, but if I put the cin in the code it will not build or run. I've never had this issue before and it's doing this with two programs: DEVC++ and CodeBlocks so I know it is something I'm doing wrong.
I searched the internet but couldn't really find an answer.
SOLVED.
--------------------------------------------
New issue sadly. Didn't want to make a whole new thread for it.
Whenever I multiply my variable by a number, the product is weird. Example, I put in 10 for seconds and I should get out 5, but I get out 15149.5 Anyone know why this is?
#include <iostream>
usingnamespace std;
int main()
{
unsignedshortint seconds;
double burned= seconds * 0.5;
cout << "Welcome to the game Calorie Burner!";
cin.get();
cout << "How many seconds would you like to run on the treadmill for? \n\n";
cin >> seconds;
cout << "\nYou will run for " << seconds << " seconds.";
cin.get();
cout << burned;
system("pause");
return 0;
}
define or assign burned after you get seconds from user. coz if you define burned as seconds*5; compiler will assign a random value to seconds(like 15468)
Thats right. When you initialize seconds, C++ wont allow it to have a value of NULL, so it gives it a random value(whatever junk value is around when you initialize) in your case seconds gets a value of 30299. Then you assign
double burned = seconds(30299) *0.5
So then burned becomes 15149.5