Answer to Question #159424 in C++ for Earl

Question #159424

Silly program: Ask the user for their age and lucky number. Add both numbers up and output the result to the user.

 

Output:

What is your age?   [assume user inputs 20]

What is your lucky number?   [assume user inputs 7]

Your lucky number added to your age is 27


1
Expert's answer
2021-01-29T03:42:33-0500
#include <iostream>

int main()
{
    std::cout << "What is your age?  ";
    int age;
    std::cin >> age;

        if(!std::cin)
        {
            std::cout << "Bad input\n";
            return 1;
        }

    std::cout << "What is your lucky number?  ";
    int number;
    std::cin >> number;

        if(!std::cin)
        {
            std::cout << "Bad input\n";
            return 1;
        }

    std::cout << "Your lucky number added to your age is " << (age + number) << "\n";
    
    return 0;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog