Student Programmer needs help help with for loop
Nov 25, 2013 at 12:57am UTC
Working on a program for class and my for loop isn't working correctly. It suppose to count the calories burned every five minutes stopping at 30minutes.
It never stops.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
int main()
{
double calsPerMin = 3.9, minutes = 5;
char again;
do
{
cout << "Minutes Calories Burned" << endl;
cout << "-------------------------------" << endl;
for ( minutes; minutes = 30; minutes*=5)
{
cout << minutes << setw(5) << calsPerMin * minutes << endl;
}
// Asks the user if they want to try again.
cout << "Would you like to try again? (y or n)" ;
cin >> again;
}while (again == 'Y' || again == 'y' );
system("pause" );
return 0;
}
Nov 25, 2013 at 2:02am UTC
http://www.cplusplus.com/doc/tutorial/control/
The for loop
Its format is:
for (initialization; condition; increase) statement;
Your for loops condition is
minutes = 30
.
and don't use doubles in a for loop you can make it
int seconds
if you need too
Last edited on Nov 25, 2013 at 2:06am UTC
Topic archived. No new replies allowed.