Done in visual studio
C++
Use C++ cout statements to ask the user to enter their
age.
Use C++ statements to read the input from the user. Do not accept
an age less than 0 or greater than 120. (print an error message and
re-prompt until you receive a valid age)
Create a for loop that prints the even numbers 2 through 20.
Create a variable calorieSum and initialize to 0. Read in calorie
values from the user and add them to the calorieSum. Stop reading
in calories when the calorieSum is greater than or equal to
2000.
Verify that your program compiles and runs with no errors
Program
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int age,calorieSum=0,calorieValue;
cout<<"Enter age: ";
cin>>age;
while((age<0)||(age>120))
{
cout<<"Enter age between 0 and 120!!!"<<endl;
cout<<"Enter age: ";
cin>>age;
}
cout<<"\nAge :"<<age<<endl;
//Even number between 0 and 20
cout<<"\nEven numbers between 0 and 20\n";
for(int i=2;i<=20;i+=2)
cout<<i<<endl;
//Calorie
while(calorieSum<=2000)
{
cout<<"\nEnter calorie value :";
cin>>calorieValue;
calorieSum+=calorieValue;
}
cout<<"\nCalorie Sum="<<calorieSum<<endl;
system("PAUSE");
return 0;
}
Done in visual studio C++ Use C++ cout statements to ask the user to enter their...