/* Program that would display two random numbers to be added, such as 247 + 129 ----------- The program will then pause until the student works on the problem. When the student is ready to check the answer, he or she can press any key and the program will display the correct solution. 247 + 129 ----------- 381 */ #include<iostream> //include "iostream" header file (for input/output functions) #include<conio.h> //include "conio.h" header file (for getch() function) #include<ctime> //for time(0) #include<cstdlib> //for srand(time(0)) #include<iomanip> //include "iomanip" header file (for output manipulation) using namespace std; int main() { int i = 0, RandNum1, RandNum2; //Declares 3 and initializes 1 int variable srand(time(0)); //This will change the random number ( rand() ) value in each execution RandNum1 = rand(); //Assigns "RandNum1" 1st Random Number RandNum2 = rand(); //Assigns "RandNum2" 1st Random Number cout << "Press any key to display \"Correct Sum\":\n"; //Display's Message cout << "\n " << setw(10) << RandNum1 << "\n+" << setw(10) << RandNum2; cout << "\n-----------"; _getch(); //Wait for user to press any key /* or cin.get(); //But in this case "Enter" Key must be pressed */ cout << "\n" << setw(11) << RandNum1 + RandNum2 << endl; //Displays Result return 0; }
OUTPUT
No comments:
Post a Comment