So i am going to have 4 questions and each question is worth 25 points and full point is 100. I am not sure how to count the answer base on my code and form score code. Thank you for helping me out. (I put 1 question to make the code shorter but in my VS there are 4 questions)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MCQuiz
{
class Program
{
static void Main(string[] args)
{
string answer;
Console.WriteLine("Q1-Every Statement in C# language must terminate with: ");
Console.WriteLine(" \t a. ; ");
Console.WriteLine(" \t b. , ");
Console.WriteLine(" \t c. . ");
Console.WriteLine(" \t d. ? ");
Console.WriteLine();
Console.Write("Enter the letter (a, b, c, d) for correct Answer: ")
answer = Console.ReadLine();
if (answer == "a")
{
Console.WriteLine("Your Answer '{0}' is Correct.", answer);
}
else
{
Console.WriteLine("Your Answer '{0}' is Wrong.", answer);
}
Console.WriteLine();
Console.WriteLine("****************************************");
}
}
}
CodePudding user response:
You could track the totalScore in an integer variable and add 25 each correct answer using the =
operator, which is a shorthand for totalScore = totalScore 25
in the following example.
class Program
{
static void Main(string[] args)
{
int totalScore = 0; // initiate variable
string answer;
Console.WriteLine("Q1-Every Statement in C# language must terminate with: ");
Console.WriteLine(" \t a. ; ");
Console.WriteLine(" \t b. , ");
Console.WriteLine(" \t c. . ");
Console.WriteLine(" \t d. ? ");
Console.WriteLine();
Console.Write("Enter the letter (a, b, c, d) for correct Answer: ")
answer = Console.ReadLine();
if (answer == "a")
{
totalScore = 25; // add score
Console.WriteLine("Your Answer '{0}' is Correct.", answer);
}
else
{
Console.WriteLine("Your Answer '{0}' is Wrong.", answer);
}
Console.WriteLine();
Console.WriteLine("****************************************");
Console.WriteLine($"You scored {totalScore} points"); // output result
}
}
CodePudding user response:
- I already created a quick maker in console application.
- Take a look Quiz maker.
- See below code snippet for you question.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MCQuiz
{
class Program
{
static void Main(string[] args)
{
string answer;
string totalScore = 0;
Console.WriteLine("Q1-Every Statement in C# language must terminate with: ");
Console.WriteLine(" \t a. ; ");
Console.WriteLine(" \t b. , ");
Console.WriteLine(" \t c. . ");
Console.WriteLine(" \t d. ? ");
Console.WriteLine();
Console.Write("Enter the letter (a, b, c, d) for correct Answer: ")
answer = Console.ReadKey();
if (answer == "a")
{
totalScore = 25;
Console.WriteLine("Your Answer '{0}' is Correct.", answer);
}
else
{
Console.WriteLine("Your Answer '{0}' is Wrong.", answer);
}
Console.WriteLine();
Console.WriteLine("****************************************");
}
}
}