/*********************************** * Ask the user to enter two * integers. Then ask the user to * calculate the sum, difference * and product of those integers. * * For each question, determine * whether the user's answer is * correct and print an appropriate * message. ***********************************/ #include // Function declarations int main(); // Function definitions int main() { int m{}; std::cout << "Enter an integer: "; std::cin >> m; int n{}; std::cout << "Enter another integer: "; std::cin >> n; // Add your code here. return 0; } // Hint: // // You will ask the user three questions and use three // conditional statements. // // For each question: // // 1. Ask the user to calculate an answer. // 2. Read the user's answer. // 3. Calculate the correct answer. // 4. Compare the two answers. // 5. Print an appropriate message. // Here is one solution: /* int main() { int m{}; std::cout << "Enter an integer: "; std::cin >> m; int n{}; std::cout << "Enter another integer: "; std::cin >> n; int user_answer{}; int correct_answer{}; // Ask for the sum. std::cout << "What is " << m << " + " << n << "? "; std::cin >> user_answer; correct_answer = m + n; if ( user_answer == correct_answer ) { std::cout << "You are correct." << std::endl; } else { std::cout << "You are incorrect: the answer is " << correct_answer << "." << std::endl; } // Ask for the difference. std::cout << "What is " << m << " - " << n << "? "; std::cin >> user_answer; correct_answer = m - n; if ( user_answer == correct_answer ) { std::cout << "You are correct." << std::endl; } else { std::cout << "You are incorrect: the answer is " << correct_answer << "." << std::endl; } // Ask for the product. std::cout << "What is " << m << " x " << n << "? "; std::cin >> user_answer; correct_answer = m*n; if ( user_answer == correct_answer ) { std::cout << "You are correct." << std::endl; } else { std::cout << "You are incorrect: the answer is " << correct_answer << "." << std::endl; } return 0; } */ // Question: // // When displaying a question such as // // What is 5 x 7? // // why might you display 'x' rather than '*' even though // multiplication must be written using '*' in C++ code? // // Remember that the text displayed to the user does not // have to use the same notation as the C++ source code.