Question

In: Computer Science

(Language: c++)Write a program that displays a question and 4 possible answers numbered 1 through 4....

(Language: c++)Write a program that displays a question and 4 possible

answers numbered 1 through 4. . The program should

ask the user to answer 1, 2, 3, or 4 and tell them if they

are correct or not. If the user enters anything besides 1, 2,

3, or 4 the program should return an error message

example outout: whats 2+5?

1. 4

2. 7

3. 1

4. 0

// if user inputs anything other then option 2 the screen should display "incorrect"

// if the user inputs anything other then 1,2,3,or 4 the screen should display "error invalid answer given"

//, when the correct answer is given computer, should display "correct".

Solutions

Expert Solution

Source code:

#include <iostream>
using namespace std;

int main()
{
   int ans=0;
   cout<<"What is 2+5 ?"<<endl;
   cout<<"1.4"<<endl;
   cout<<"2.7"<<endl;
   cout<<"3.1"<<endl;
   cout<<"4.0"<<endl;
   cin>>ans;
   if(ans!=1 && ans!=2 && ans!=3 && ans!=4)
   {
       cout<<"error invalid answer given"<<endl;
   }
   else
   {
       if(ans==2)
       {
           cout<<"correct"<<endl;
       }
       else
       {
           cout<<"incorrect"<<endl;
       }
   }

}

Sample input and output:


Related Solutions

4. Suppose there are 99 lockers numbered 1 through 99, and 99 students numbered 1 through...
4. Suppose there are 99 lockers numbered 1 through 99, and 99 students numbered 1 through 99. Initially, all lockers are closed. Now each odd-numbered student 1, 3, 5, 7, · · · , 99, in numerical order from 1 through 99, will open/close all the lockers that are numbered to be a multiple of the number of the student. For example, student 1 will open/close all the lockers, and student 3 will open/close all the lockers numbered by 3,...
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a...
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an inpatient or an outpatient. If the patient was an inpatient, the following data should be entered: The number of days spent in the hospital The daily rate Hospital medication charges Charges for hospital services (lab tests, etc.) The program should ask for the following data if the patient was...
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that...
Complete Question 1a-c 1a) Write a C program that displays all the command line arguments that appear on the command line when the program is invoked. Use the file name cl.c for your c program. Test your program with cl hello goodbye and cl 1 2 3 4 5 6 7 8 and cl 1b) Write a C program that reads in a string from the keyboard. Use scanf with the conversion code %s. Recall that the 2nd arg in...
Please use Java language! with as much as comment! thanks! Write a program that displays a...
Please use Java language! with as much as comment! thanks! Write a program that displays a frame with a three labels and three textfields. The labels should be "width:", "height:", and "title:" and should each be followed by one textfield. The texfields should be initialized with default values (Example 400, 600, default title), but should be edited by the user. There should be a button (label it whatever you want, I don't care). If you click the button, a new...
Please use Java language! with as much as comment! thanks! Write a program that displays a...
Please use Java language! with as much as comment! thanks! Write a program that displays a frame with a three labels and three textfields. The labels should be "width:", "height:", and "title:" and should each be followed by one textfield. The texfields should be initialized with default values (Example 400, 600, default title), but should be edited by the user. There should be a button (label it whatever you want, I don't care). If you click the button, a new...
c++ Write a program that displays the status of an order. a) Program uses 2 functions...
c++ Write a program that displays the status of an order. a) Program uses 2 functions (in addition to main ()). b) The first function asks the user for the data below and stores the input values in reference parameters. c) Input data from user: # of spools ordered, # of spools in stock, any special shipping & handling charges over and above the $10 rate. d) The second function receives as arguments any values needed to compute and display...
C++ Write a program that displays the follow menu: Geometry Calculator    1. Calculate the Area...
C++ Write a program that displays the follow menu: Geometry Calculator    1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle    3. Calculate the Area of a Triangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle then display it's area using the following formula: area = PIr2 Use 3,14159 for PI and the radius of the circle for r. If the...
Write a program for multiplication quiz. It displays to the student a question such as “What...
Write a program for multiplication quiz. It displays to the student a question such as “What is 5 × 19?”. After the student enters the answer, the program displays a message indicating whether it is correct. Note: you can use Math.random() to obtain a random integer value between 0 and 100. JAVA
C# language Question: You need to write a program for students who receive bursaries in the...
C# language Question: You need to write a program for students who receive bursaries in the department, managing the free hours they have to do. For each recipient you store the recipient’s name and the number of hours outstanding. All recipients start with 90 hours. Implement class Recipients which has the private attributes Name and Hours. In addition to the constructor, the class has the following methods: public String getName() // Returns the name of the recipient public int getHours()...
Write a C++ program that asks the user to enter in three numbers and displays the...
Write a C++ program that asks the user to enter in three numbers and displays the numbers in ascending order. If the three numbers are all the same the program should tell the user that all the numbers are equal and exits the program. Be sure to think about all the possible cases of three numbers. Be sure to test all possible paths. Sample Runs: NOTE: not all possible runs are shown below. Sample Run 1 Welcome to the order...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT