Reputation: 309
Im building a console c# flash card game and I want to keep a score going to show at the end of how many where correct. I am thinking on what is the best course of action to do this I was thinking a for loop but it didn't work for me like I thought that it might and then again I am still new to programming so I am sure maybe I am just doing something wrong.
So, I have a double called answer. and since I only need a single in I used another int that is called correctAnswer. I was thinking I could use that to add to the for loop but it didn't go as planned so, I am just asking for what might be the best course of action to add points to a score. I also see another problem I will have by using answer as it will add a point even if they get it wrong but I can fix that once I get this sorted.
double answer = 0;
int correctAnswer = Convert.ToInt32(answer);
for (correctAnswer = 0; correctAnswer <= answer; correctAnswer++) ;
///Setting up the switch statement
///switch (variable)
/// case 1:
/// code;
/// break;
///
switch (opSign)
{
case 1:
Console.WriteLine("What is the answer to " + num1 + (" Times " + num2 + " ?"));
answer = Convert.ToInt32(Console.ReadLine());
if (answer == num1 * num2)
{
speechAnswers();
Console.WriteLine("You entered " + answer + " as the answer to " + num1 + " times " + num2 + "." + " You are correct good job! ");
}
else if (answer != num1 * num2)
Console.WriteLine("You are incorrect please try again");
break;
Upvotes: 0
Views: 2299
Reputation: 2130
This your the code after adding a small bit of code. Every time he answers correctly, Answer is incremented by 1. If you want to reset your score, You will need to make a function for that that happens when maybe, score decreases three times in a streak. This is your game.
double answer = 0;
int correctAnswer = Convert.ToInt32(answer);
for (correctAnswer = 0; correctAnswer <= answer; correctAnswer++) ;
///Setting up the switch statement
///switch (variable)
/// case 1:
/// code;
/// break;
///
switch (opSign)
{
case 1:
Console.WriteLine("What is the answer to " + num1 + (" Times " + num2 + " ?"));
answer = Convert.ToInt32(Console.ReadLine());
if (answer == num1 * num2)
{
speechAnswers();
Console.WriteLine("You entered " + answer + " as the answer to " + num1 + " times " + num2 + "." + " You are correct good job! ");
score += 1; // every time the answer is correct, score is incremented by 1.
}
else if (answer != num1 * num2)
Console.WriteLine("You are incorrect please try again");
// what happens on loss
break;
every time you write a code happens when the answer is correct, Add this
score += 1;
Upvotes: 1