Create C# program with two multiple choice questions. The program MUST include t
ID: 3847759 • Letter: C
Question
Create C# program with two multiple choice questions.
The program MUST include the following features:
1. Users have 2 ATTEMPTS ONLY , show attmpt number each time. Use: while loop with break control.
2. Only one correct answer for each question, use switch case for each question.
3. Show total score after the 2 questions are answered. Use: if...else if...else.
4. User have options to answer the two questions again if first attempt score is not 100%. Use: if statement.
5. Use string method .ToUpper() to allow users to enter with lowercase or uppercase letters.
Output -----------------------------------------
After re-opening the program:
CAWIN Multiple choice Questions select only one answer in each question (Note you have two attempts total, attempt 1) 1. Where is the capital of the state of Florida? A. Orlando B. Tallahassee C. Miami D. Tampa Answer: C 2. Where is Walt Disney World Park located in Florida? A. Orlando B. Tallahassee C. Miami D. Tampa Answer: Your score is: 0 Would you like to try one more time? (Y/N):Explanation / Answer
using System;
public class Test
{
public static void Main()
{
string answer = " ";
string option = " ";
int score = 0;
int tries = 0;
do
{
score = 0;
Console.WriteLine("Multiple choice questions, select one answer in each question. (Note: You have 2 attempts, ATTEMPT :"+(tries+1));
Console.WriteLine("1. Where is the capital of the State of Florida ?");
Console.WriteLine("A. Orlando");
Console.WriteLine("B. Tallahassee");
Console.WriteLine("C. Miami");
Console.WriteLine("D. Tempa");
Console.WriteLine("Answer: ");
answer = Console.ReadLine().ToUpper(); //read answer and convert it to uppercase
switch(answer)
{
case "A" :
break;
case "B" :score = score +1; //add 1 to score if answer is correct
break;
case "C" :
case "D" :
break;
default :Console.WriteLine("Invalid answer ");
break;
}
Console.WriteLine("2. Where is Walt Disney World Park Located in Florida ?");
Console.WriteLine("A. Orlando");
Console.WriteLine("B. Tallahassee");
Console.WriteLine("C. Miami");
Console.WriteLine("D. Tempa");
Console.WriteLine("Answer: ");
answer = Console.ReadLine().ToUpper();
switch(answer)
{
case "A" : score = score +1;//add 1 to score if answer is correct
break;
case "B" :
case "C" :
case "D" :break;
default :Console.WriteLine("Invalid answer");
break;
}
Console.WriteLine("Your score is "+ (score/2 *100) +"%");
tries++; //increment tries
Console.WriteLine(" Would you like to try one more time? (Y/N):");
option = Console.ReadLine().ToUpper();
if(option != "Y")
break;
}while(option != "N" && tries<=2);
}
}
Output:
Multiple choice questions, select one answer in each question. (Note: You have 2 attempts, ATTEMPT :1
1. Where is the capital of the State of Florida ?
A. Orlando
B. Tallahassee
C. Miami
D. Tempa
Answer: a
2. Where is Walt Disney World Park Located in Florida ?
A. Orlando
B. Tallahassee
C. Miami
D. Tempa
Answer: b
Your score is 0%
Would you like to try one more time? (Y/N) y
Multiple choice questions, select one answer in each question. (Note: You have 2 attempts, ATTEMPT :2
1. Where is the capital of the State of Florida ?
A. Orlando
B. Tallahassee
C. Miami
D. Tempa
Answer: b
2. Where is Walt Disney World Park Located in Florida ?
A. Orlando
B. Tallahassee
C. Miami
D. Tempa
Answer: a
Your score is 100%
Would you like to try one more time? (Y/N) n