Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

an-introduction-to-programming-with-cpp-8th-edition.pdf-Adobe Acrobat Reader DC

ID: 3689483 • Letter: A

Question

an-introduction-to-programming-with-cpp-8th-edition.pdf-Adobe Acrobat Reader DC File Edit View Window Help Sign In Home ools an-introduction-to-... × 324 (344 of 628) Over 100 4.99 Export PDF 0-49.99 Over 49.99 Premium 4.99 Adobe Export PDF Convert PDF Files to Word or Excel Online Figure 9-42 Select PDF File Create a program that displays five random addition problems, one at a time, on the computer screen. Each problem should be displayed as a question, like this: What is the sum of x + y?. The x and y in the question represent random numbers from 1 to 10 inclusive. After displaying the question, the program should allow the user to enter the answer. It should then compare the user's answer with the correct answer. If the user's answer matches the correct answer, the program should display the "Correct!" message. Otherwise, it should display the "Sorry, the answer is" message followed by the correct answer and a period. If necessary, create a new project named Advanced24 Project, and save it in the Cpp8Chap09 folder. Enter your C++ instructions into a source file named Advanced24.cpp. Also enter appropriate comments and any additional instructions required by the compiler. Test the program appropriately 24. ADVANCED an-introduct...-edition·pdf × Convert to Microsoft Word(.docx) Document Language English (U.S.) Change Convert In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer, as shown in Figure 9-43. For a residential cus- tomer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate program-defined function for each customer type. 25. ADVANCED Create PDF Edit PDF Comment Store and share files in the Document Cloud Learn More 12:45 PM Ask me anything 4/14/2016

Explanation / Answer

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void checkAnswer(int answer, int userAnswer);
int generateQuestion();
int x;
int y;
int main(int argc, char *argv[])
{
srand (time(NULL));
for(int i=0;i<5;i++)
{
int answer;
int userAnswer;
answer = generateQuestion();
cin>>userAnswer;
checkAnswer(answer,userAnswer);
}
return 0;
}
int generateQuestion()
{
int answer;
x = 1 + rand()%10;
y = 1 + rand()%10;
answer=x+y;
cout<<"What is the sum of "<<x <<"+"<< y<<"?";
return answer;
}
void checkAnswer(int answer, int userAnswer)
{
if(answer == userAnswer)
{
cout<<"Correct! ";
}
else if(answer != userAnswer)
{
cout<<"Sorry, the answer is "<<answer<<". ";
}
}