Question

Done in visual studio C++ Use C++ cout statements to ask the user to enter their...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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;

}

Add a comment
Know the answer?
Add Answer to:
Done in visual studio C++ Use C++ cout statements to ask the user to enter their...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT