So the task of the program is:
Design and implement a program that asks the user to enter a number and then guess at the square of the first number. If the user guesses correctly a congratulatory message is displayed, otherwise a commiseration message is displayed along with the correct answer.
This is how I tried to design a program:
C++ Code:
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using namespace std;
- int main ()
- {
- int number1;
- int number2;
- std::cout<<"Enter number to be squared: ";
- std::cin>>number1;
- std::cout<<"Guess the square: ";
- std::cin>>number2;
- If (number2==number1*number1);
- std::cout<<"Good Guess"<<endl;
- If (number2!=number1*number1);
- std::cout<<"Not Correct."<<number1<<"squared is"<<number1*number1<<endl;
- system("pause");
- return 0;
- }