Calculate how much calories you burn

Running on a particular treadmill you burn 3.9 calories per minute. Write a program that uses a
loop to display the number of calories burned after 10, 15, 20, 25, and 30 minutes.
My code is wrong because when i started it, it gave me wrong and weird result. Can anyone help me rewrite it correctly?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>

using namespace std;

int main ()

{

int i = 0;

do

{

double calories = i * 3.90;

cout << calories << " burnt after " << i << " minute(s)" << endl;

i++;

} while(i <= 30);

system("pause");

return 0;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>

int main()
{
  for(int i = 10; i <= 30; i += 5)
    std::cout<<i*3.9<< " calories burnt after: "<<i<<" minutes.\n";

  std::cout<<"Press enter to continue...\n";
  std::string s; 
  std::getline(std::cin, s);

  return 0;
}
@nhikull

I compiled an ran ran correctly, for me, though it calculated and showed the total calories burnt, every minute. You should put a if statement to show the results, ONLY if i is equal to the minutes desired. Also, you could declare double calories, after your int i declaration, and calculate the calories in the do loop , without the added 'double' declaration.
Why do you return 0 when you use that windows only function?

Don't use system, even for homework, it's bad practice.
I am learning about the "loop" and it really hard. So that is how you write a loop, because when i did this for the first time he said i was so wrong.
#include<iostream>
using namespace std;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
int i,n;
char ch;
double cal;
do
{
    cin>>n;
    cal=n*3.90;
    cout<<cal<<endl;
    cout<<"want to continue: Y or N\n";
    cin>>ch;
}while(ch=='Y');
return 0;
}

it worked but i gotta keep punching in values everytime and he does't told the class what is he expecting. :(
Last edited on
Topic archived. No new replies allowed.