In: Computer Science
C# in Visual Studio
Practice Concepts
● Practice using conditional logic and expressions
● Practice protecting numeric input prompts (Int.TryParse(Console.ReadLine(), out);
Problem Description
create a Console Application using the .NET Framework. C#
This project will implement a short 3-question quiz.
Create a quiz application that has 3 questions. At least one of the questions must offer multiple choices,
and at least one question must prompt the user to enter a numeric input. The third question can be
either multiple choice or numeric input.
Scoring a multiple choice question will work as follows:
● If the user enters the correct choice value, award 3 points.
● If the user enters a valid offered choice, but the incorrect answer, award 1 point.
● If the user enters an invalid option, award 0 points.
Scoring a numeric input question will work as follows:
● If the user enters the correct numeric value, award 3 points.
● If the user enters a valid number, but the incorrect answer, award 1 point.
● If the user enters a non-numeric value, award 0 points.
Final scoring:
● If the user answered all three questions correctly, award 1 bonus point, for a maximum of 10
points earned. (3 points for each correct answer, plus the bonus point).
Test Conditions
● Your program should be free of syntax errors and build and compile properly.
● Due to the numerous ways you can answer these questions, make sure to test your program
over multiple conditions. Test the case where all answers are correct, all answers are incorrect,
etc.
● Note: On this quiz, it should be possible to score: 0 points, 1 point, 2 points, 3 points, 4 points,
5 points, 6 points, 7 points, and 10 points. Can you test each case?
/*C # program that prompts the user to enter choice for
multiple-choice question, one numeric question and then
multiple-choice question. If all three questions are correct, then
award 10 points. Otherwise set points as per the given
instructions.*/
//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QuizTest
{
class Program
{
static void Main(string[] args)
{
//declaration of variables
int choice;
int userInputValue;
int CORRECT_ANSWER = 3;
int WRONG_ANSWER = 1;
int INVALID=0;
int BONUS_POINT = 1;
bool all_correct = true;
int points=0;
//Question1: Multiple choice
Console.WriteLine ("1.What is value of earth gravitational constant
?");
Console.WriteLine("1){0,-20}2){1,-20}3){2,-20}4){3,-20}", "9.807
m/s²", "10.807 m/s²", "11.807 m/s²", "12.807 m/s²");
Console.WriteLine("Answer : ");
if (int.TryParse(Console.ReadLine(), out choice))
{
if (choice == 1)
points = points + CORRECT_ANSWER;
else if (choice == 2 || choice == 3 || choice == 4)
{
all_correct = false;
points = points + WRONG_ANSWER;
}
}
else
{
all_correct = false;
points = points + INVALID;
}
//Question2: Numeric type
Console.WriteLine("\n2.What is size of /'char/' in C #
programming?");
Console.Write("Answer : ");
if (int.TryParse(Console.ReadLine(), out userInputValue))
{
//check if user entered correct answr
if (userInputValue == 2)
//Add 3 points
points = points + CORRECT_ANSWER;
else if (userInputValue < 0)
{
//Add 1 points
points = points + WRONG_ANSWER;
all_correct = false;
}
}
else
{
all_correct = false;
points = points + INVALID;
}
//Question3: Multiple choice
Console.WriteLine("\n\n3.What is size of integer in c# programming
?");
Console.WriteLine("1){0,-20} 2){1,-20} 3){2,-20} 4){3,-20}", "2
Bytes", "4 Bytes", "6 Bytes", "8 Bytes");
Console.WriteLine("Answer : ");
//Check if user choice is valid
if (int.TryParse(Console.ReadLine(), out choice))
{
//check if user entered correct answr
if (choice == 2)
//Add 3 points
points = points + CORRECT_ANSWER;
//valid choice but incorrect answer
else if (choice ==1 || choice == 3 || choice == 4)
{
//set boolean to false
all_correct = false;
//Add 1 points
points = points + WRONG_ANSWER;
}
}
else
{
all_correct = false;
points = points + INVALID;
}
if(all_correct)
Console.WriteLine("\nTotal points scored : {0} ",
points+BONUS_POINT );
else
Console.WriteLine("\nTotal points scored : {0} ", points);
Console.ReadKey();
}
}
}
------------------------------------------------------------------------------------------------------------------------
Sample Output: