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

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...
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()...
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays...
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays the sum and the difference. In the .data section, define two variables num1 and num2 both words. Initialize num1 to 92413 10 and num2 to D4B 16 (use 0xD4B to initialize, Note that D4B is a hexadecimal number). Your main procedure/function should load the values of num1 and num2 into two temporary registers, and display them on the console window. Then add the values...
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
Write a program in C language 1- Define a struct for students with the aforementioned attributes,...
Write a program in C language 1- Define a struct for students with the aforementioned attributes, test it by populating one initialized struct variable with arbitrary input and take screenshots of the output. 2- For each student, struct add an array of number grades for a class the students are enrolled in such as S E 185. Then write functions which find the max, average, and minimum score for a specified assignment identified by a number, for example, Assignment 0...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
C++ Overloaded Hospital Write a program that computes and displays the charges for a patient’s hospital...
C++ Overloaded Hospital Write a 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 in-patient or an out-patient. Please keep asking the user until the user enters the valid choice. Please refer to the test cases for more details. If the patient was an in-patient the following data should be entered: • The number of days spent in the hospital • The daily rate •...
Write a program in C++ that asks the user for his/her Taxable Income and displays the...
Write a program in C++ that asks the user for his/her Taxable Income and displays the Income Tax owed. Use the following table to calculate the Income Tax: Taxable Income Tax Rate $0 to $9,225 / 10% $9,226 to $37,450 / $922.50 plus 15% of the amount over $9,225 $37,451 to $90,750 / $5,156.25 plus 25% of the amount over $37,450 $90,751 to $189,300 / $18,481.25 plus 28% of the amount over $90,750 $189,301 to $411,500 / $46,075.25 plus 33%...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT