loop problem with treadmill

i was trying to make a simple treadmill calculation for myself by seeing how much a person could burn in 10 15 20 25 and then 30 minutes at 3.9 calories but i keep getting a strange number of 5.67292e-294 or when i switch them i get nothing. that makes no since i think the problem is the loop but i don't see whats wrong can some one give me a clue?



#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{

double burnd = 3.9;
double time = 30;
double calories;


if (burnd >= time && burnd <= 5)
{
calories = burnd * time;
time++;



}

cout<<"my rate of burn is "<< calories <<endl;




return 0;

}
First off, please put [code][/code] around your code for line numbers. Or you can click the # sign when you are posting.

Calories is not set to a value and your if is never true. Therefore what is being displayed is that undefined garbage stuff. Also you do not have a loop in your code. I think you meant your if to be a while.

Last edited on
hmm I'm still having trouble even if it is a while statement
1
2
3
4
5
if (burnd >= time && burnd <= 5)
{
calories = burnd * time;
time++;
} 


This can never be true. Because burnd (shouldn't it be burnt?) is not set as >= time AND <= 5.

Having a while loop will do nothing, until you fix the condition. You also need to ensure you have a way to get out of the while loop, or it will run forever.
i got the loop figured out but I'm still getting an error near if statement.



#include<iostream>
#include<iomanip>

using namespace std;
int main()

{

[/code]int i;
[/code]float calori = i * 3.9;


[/code]cout<<"the rate of burn calculator"<<endl;




[/code]for (i = 0; i < 30; i++)
[/code]{
[/code]float calori = i * 3.9;
[/code] if (i % 5 = 0)

[/code] cout << i <<" "<< calori <<endl;

[/code]}

[/code]return 0;

}
Ok. To post code do it like this [c0de] your code goes here [/c0de] . but replace the 0 with c0de with o, so it's code. Make sense?

As for your code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<iostream>
#include<iomanip>

using namespace std;

int main() {
int i;
float calori = i * 3.9;

cout<<"the rate of burn calculator"<<endl;

for (i = 0; i < 30; i++) {
 float calori = i * 3.9;
 if (i % 5 = 0)
  cout << i <<" "<< calori <<endl;
}

 return 0;
}


It'd be better like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#include<iostream>

using namespace std;

int main() {

cout<<"the rate of burn calculator"<<endl;

for (int i = 0; i < 30; i+=5) {
 float calori = i * 3.9;
 cout << i <<" "<< calori <<endl;
}

 return 0;
}
thanks is finally works now i can begging expanding it from my family
Topic archived. No new replies allowed.