I generate my random numbers with the Random num1 = new Random() method. I wanted to know if there was any way to have something like 10 different questions, each corresponding to a possible number. For example, when the random number 1 is generated, I want the question "What is the fastest animal?". I was able to do this quite easily, but every time I did the Console.ReadLine(); right afterward, the question before that changes on me. An example of what this would look like is this:
What is the fastest animal? > and then once I answered, it would show something like this:
An elephant's diet consists mostly of what? cheetah. How can I fix this?
Here is my code:
public class Program
{
public static void Main()
{
string[] incorrectAnswersJediSimple = new string[5];
Random JediS1 = new Random();
int randJediS1 = JediS1.Next(1, 4);
int totalScore = 0;
string JediQ11 = "JediQ11";
switch(randJediS1){
case 1:
JediQ11 = "Who is Luke Skywalker's father? ";
Console.Write(JediQ11);
string JediQ111 = Console.ReadLine();
if (JediQ111.Equals("Darth Vader", System.StringComparison.OrdinalIgnoreCase) || JediQ111.Equals("Vader", System.StringComparison.OrdinalIgnoreCase) || JediQ111.Equals("Anakin Skywalker", System.StringComparison.OrdinalIgnoreCase) || JediQ111.Equals("Anakin", System.StringComparison.OrdinalIgnoreCase)) {
totalScore++;
} else {
incorrectAnswersJediSimple[0] = "#1";
}
break;
case 2:
JediQ11 = "Who is Luke Skywalker's sister? ";
Console.Write(JediQ11);
string JediQ112 = Console.ReadLine();
if (JediQ112.Equals("Princess Leia", System.StringComparison.OrdinalIgnoreCase) || JediQ112.Equals("Leia", System.StringComparison.OrdinalIgnoreCase) || JediQ112.Equals("Leia Organa", System.StringComparison.OrdinalIgnoreCase) || JediQ112.Equals("Leia Skywalker", System.StringComparison.OrdinalIgnoreCase) || JediQ112.Equals("Princess Leia Organa", System.StringComparison.OrdinalIgnoreCase) || JediQ112.Equals("Princess Leia Skywalker", System.StringComparison.OrdinalIgnoreCase)) {
totalScore++;
} else {
incorrectAnswersJediSimple[0] = "#1";
}
break;
case 3:
JediQ11 = "What is Darth Vaders real name? ";
Console.Write(JediQ11);
string JediQ113 = Console.ReadLine();
if (JediQ113.Equals("Anakin Skywalker", System.StringComparison.OrdinalIgnoreCase) || JediQ113.Equals("Anakin", System.StringComparison.OrdinalIgnoreCase) || JediQ113.Equals("Ani boi", System.StringComparison.OrdinalIgnoreCase) || JediQ113.Equals("ani", System.StringComparison.OrdinalIgnoreCase)) {
totalScore++;
} else {
incorrectAnswersJediSimple[0] = "#1";
}
break;
case 4:
JediQ11 = "What species is Admiral Ackbar? ";
Console.Write(JediQ11);
string JediQ114 = Console.ReadLine();
break;
case 5:
JediQ11 = "Who is Han Solo's Wookie sidekick? ";
Console.Write(JediQ11);
string JediQ115 = Console.ReadLine();
break;
case 6:
JediQ11 = "What species is Jar Jar Binks? ";
Console.Write(JediQ11);
string JediQ116 = Console.ReadLine();
break;
case 7:
JediQ11 = "On what planet does Luke first find Yoda in the original trilogy? ";
Console.WriteLine(JediQ11);
string JediQ117 = Console.ReadLine();
break;
case 8:
JediQ11 = "Who is Rey's grandfather? ";
Console.Write(JediQ11);
string JediQ118 = Console.ReadLine();
break;
case 9:
JediQ11 = "Who threw Mace Windu out of a window? ";
Console.Write(JediQ11);
string JediQ119 = Console.ReadLine();
break;
case 10:
JediQ11 = "What planet is Jedi Master Plo Koon from? ";
Console.Write(JediQ11);
string JediQ1110 = Console.ReadLine();
break;
default:
JediQ11 = "ERROR";
Console.WriteLine(JediQ11);
Console.Write("\nPress any key to continue...");
string ERROR11 = Console.ReadLine();
break;
}
}
}```
Related
internal class Program
{
static void Main(string[] args)
{
double result = 0;
Console.WriteLine("Welcome to the Physics calculator!");
Console.WriteLine("Please choose one of the following options");
Console.WriteLine("1.Unit Conversions");
Console.WriteLine();
Console.WriteLine("What is the current form of the number you are trying to convert?");
Console.WriteLine("1.Coulomb");
Console.WriteLine("2.mCoulomb");
Console.WriteLine("3.μCoulomb");
Console.WriteLine("4.nCoulomb");
Console.WriteLine("5.pCoulomb");
string answer1 = Console.ReadLine();
double answerbase = 0;
double answerpow = 0;
switch (answer1)
{
case "1":
Console.WriteLine("Please continue to the next part");
answerbase = Convert.ToDouble(Console.ReadLine());
break;
case "2":
Console.WriteLine("Please enter the number: ");
answerbase = Convert.ToDouble(Console.ReadLine());
break;
case "3":
Console.WriteLine("Please enter the number: ");
answerbase = Convert.ToDouble(Console.ReadLine());
break;
case "4":
Console.WriteLine("Please enter the number: ");
answerbase = Convert.ToDouble(Console.ReadLine());
break;
case "5":
Console.WriteLine("Please enter the number: ");
answerbase = Convert.ToDouble(Console.ReadLine());
break;
default:
Console.WriteLine("That is not a valid option!");
break;
}
Console.WriteLine("In which for would you like to convert your number?");
Console.WriteLine("Choose one of the following options");
Console.WriteLine("1.Coulomb");
Console.WriteLine("2.mCoulomb");
Console.WriteLine("3.μCoulomb");
Console.WriteLine("4.nCoulomb");
Console.WriteLine("5.pCoulomb");
string answer2 = Console.ReadLine();
//Console.WriteLine("Please input your number");
//double answer3 = Convert.ToDouble(Console.ReadLine());
double resultconversion = 0;
while (answer1 == "1")
{
if (answer1 == answer2)
{
Console.WriteLine("No conversion neeeded!");
}
else if (answer1 != answer2)
{
switch (answer2)
{
case "2":
answerpow = 10 ^ -3;
resultconversion = Math.Pow(answerbase, answerpow);
break;
case "3":
answerpow = 10 ^ -6;
resultconversion = Math.Pow(answerbase, answerpow);
break;
case "4":
answerpow = 10 ^ -9;
resultconversion = Math.Pow(answerbase, answerpow);
break;
case "5":
answerpow = 10 ^ -12;
resultconversion = Math.Pow(answerbase, answerpow);
break;
}
}
}
while(answer1 == "2")
{
if (answer1 == answer2)
{
Console.WriteLine("No conversion needed");
}
else if (answer1 != answer2)
switch (answer2) //line 107
{
case "1":
answerpow = 10 ^ 3;
resultconversion = answerbase/(10 ^ 3);
break;
case "3":
answerpow = 10 ^ 6;
resultconversion = Math.Pow(answerbase, answerpow);
break;
case "4":
answerpow = 10 ^ 9;
resultconversion = Math.Pow(answerbase, answerpow);
break;
case "5":
answerpow = 10 ^ 12;
resultconversion = Math.Pow(answerbase, answerpow);
break;
}
}
Console.WriteLine($"The result in an int form: {answerbase}^{answerpow}");
Console.WriteLine($"The number {answerbase} is raised to the power of {answerpow}");
Console.WriteLine("The result in decimal for: " + resultconversion);
}
}
The problem that I face is that when I reach line 107 my code freezes and nothing happens. I am not sure what's happening. Please note that the code is incomplete and the working functions as of right now are only the first and half of the second. I am a beginner and I would appreciate if you would not critisise me for not discovering the problem.
I added a while loop so for each answer specific things would happen. But inside the second while loop something seems to be broken inside the first switch case at line 107. When I input the form of the current number as mCoulomb and the form I am trying to convert it to Coulomb the program just freezes.
The problem is simple, you have a while loop on answer1 but you are not modifying it anywhere in your code. and that is the reason it is becoming an infinite loop. you can either add a break at the end of each while loop (you need to check this first). or modify the answer1 so that it may come out of the loop.
Vivek's answer is correct as to what's happening in your program. You should mark his answer as correct.
I'm posting this as a way for you to see how this code can get written.
string unit = "Coulomb";
var factors = new[]
{
new { name = "", magnitude = 0 },
new { name = "m", magnitude = -3 },
new { name = "μ", magnitude = -6 },
new { name = "n", magnitude = -9 },
new { name = "p", magnitude = -12 },
};
string[] header1 = new string[] { "Welcome to the Physics calculator!", "Please choose one of the following options", "1.Unit Conversions", "", "What is the current form of the number you are trying to convert?", };
string[] header2 = new string[] { "In which for would you like to convert your number?", "Choose one of the following options", };
int GetFactorIndex(string[] header)
{
Console.WriteLine(String.Join(Environment.NewLine, header.Concat(factors.Select((x, n) => $"{n + 1}. {x.name}{unit}"))));
return int.Parse(Console.ReadLine()) - 1;
}
int index1 = GetFactorIndex(header1);
Console.WriteLine("Please enter the number: ");
double value = double.Parse(Console.ReadLine());
int index2 = GetFactorIndex(header1);
int magnitude = factors[index1].magnitude - factors[index2].magnitude;
double factor = Math.Pow(10.0, magnitude);
double answer = value * factor;
Console.WriteLine($"The number {value} {factors[index1].name}{unit} is multiplied by {factor}");
Console.WriteLine($"The result in value of: {answer} {factors[index2].name}{unit}");
That's it. I think it is working correctly. Let me know if there are any issues you discover.
I want to add switch case to not allow the user to write string when entering temperature or when there is nothing to delete it says "there is nothing to delete, go back to menu".
List<string> Temp = new List<string>();
while (true)
{
string val;
Console.WriteLine("[L] ägg till temp-mätning: ");
Console.WriteLine("[S] kriv ut alla temperaturer och medeltemperatur");
Console.WriteLine("[T] ag bort temp-mätning");
Console.WriteLine("[A] vsluta");
Console.Write("Selection: ");
val = Console.ReadLine();
if (val == "l" || val == "L")
{
Console.WriteLine("add temperature : ");
Temp.Add(Console.ReadLine());
Console.Clear();
}
else if(val == "s" || val == "S")
{
int index = 1;
Console.Clear();
Console.WriteLine($"Your temperatures are: ");
Temp.ForEach(x => Console.WriteLine($"{index++} - {x}"));
}
else if (val == "t" || val == "T")
{
Console.Write($"Which temp do you want to delete [index from 1 to {Temp.Count}]: ");
int deleteIndex = int.Parse(Console.ReadLine()) - 1;
Temp.RemoveAt(deleteIndex);
}
else
{
Console.WriteLine("incorrect input: ");
Console.Clear();
break;
}
To control use input you can extract methods, e.g.
private static int ReadInteger(string title) {
while (true) {
if (!string.IsNullOrWhiteSpace(title))
Console.WriteLine(title);
if (int.TryParse(Console.ReadLine(), out int result))
return result;
Console.WriteLine("Incorrect syntax, please, try again.");
}
}
then you can put
val = Console
.ReadLine()
.Trim() // Let's be nice and tolerate leading / trailing spaces, e.g. " L "
.ToUpper();
val = val.Substring(0, Math.Max(1, val.Length));
switch (val) {
case "L":
// We read valid integer, turn it to string and out to Temp
Temp.Add(ReadInteger("add temperature : ").ToString());
Console.Clear();
break;
case "T":
int deleteIndex = ReadInteger(
"$"Which temp do you want to delete [index from 1 to {Temp.Count}]: ");
if (deleteIndex >= 0 && deleteIndex < Temp.Count)
Temp.RemoveAt(deleteIndex);
else
Console.WriteLine("Index out of range");
break;
...
}
Please check C# reference websites or books before asking questions.
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/
Here is the code you wanted, hope this helps you:
List<string> Temp = new List<string>();
while (true)
{
menu:
string val = string.Empty;
Console.WriteLine("[L] ägg till temp-mätning: ");
Console.WriteLine("[S] kriv ut alla temperaturer och medeltemperatur");
Console.WriteLine("[T] ag bort temp-mätning");
Console.WriteLine("[A] vsluta");
Console.Write("Selection: ");
val = Console.ReadLine();
switch (val.ToLower())
{
case "l":
addTemperature:
Console.WriteLine("add temperature : ");
string temperatureInput = Console.ReadLine();
int temperatureToAddToList;
try
{
temperatureToAddToList = Convert.ToInt32(temperatureInput); //This line trys to convert string variables to integer variables. If string variable includes any character, it will throw an exception.
}
catch (Exception error) //If an exception was thrown, this code block gets activated, which will give out the message you asked for.
{
Console.Clear();
Console.WriteLine("Please enter a number instead of a string!");
goto addTemperature;
}
Temp.Add(temperatureInput.Trim());
Console.Clear();
break;
case "s":
int index = 1;
Console.Clear();
Console.WriteLine($"Your temperatures are: ");
Temp.ForEach(x => Console.WriteLine($"{index++} - {x}"));
break;
case "t":
if (Temp.Count == 0)
{
Console.Clear();
Console.WriteLine("There is nothing to delete, go back to menu.");
goto menu;
}
else
{
Console.Write($"Which temp do you want to delete [index from 1 to {Temp.Count}]: ");
int deleteIndex = int.Parse(Console.ReadLine()) - 1;
Temp.RemoveAt(deleteIndex);
break;
}
default:
Console.WriteLine("incorrect input: ");
Console.Clear();
break;
}
I have revised and updated my code example to better solve your problem.
C # do while question.
What I want is the ability to terminate Q or q in upper case, lowercase letters in the source code.
I referenced MSDN but it did not work out, so I have a question here.
Thank you.
using System;
namespace Try
{
class Program
{
static void Main(string[] args)
{
string str1 = "Q";
string str2 = "q";
if (str1.Equals(str2, StringComparison.OrdinalIgnoreCase)) { }
string menu = "";
do
{
Console.WriteLine("Select Meun:(1)Triangle (2)Rectangle " +
"(Q)Quit",string.Equals
(str1, str2, StringComparison.CurrentCultureIgnoreCase));
menu = Console.ReadLine();
Console.WriteLine(menu + "is selected");
} while (menu != "Q");
}
}
}
Option 1
while (!string.Equals(menu, "Q", StringComparison.OrdinalIgnoreCase));
As the StringComparision suggests, this will ignore the case and treat q and Q as the same.
static void Main(string[] args)
{
string str1 = "Q";
string str2 = "q";
if (str1.Equals(str2, StringComparison.OrdinalIgnoreCase)) { }
string menu = "";
do
{
Console.WriteLine("Select Meun:(1)Triangle (2)Rectangle " +
"(Q)Quit",string.Equals
(str1, str2,
StringComparison.CurrentCultureIgnoreCase));
menu = Console.ReadLine();
Console.WriteLine(menu + "is selected");
} while (!string.Equals(menu, "Q", StringComparison.OrdinalIgnoreCase));
}
Option 2
while (menu.ToUpper() != "Q")
This will convert anything that is in the variable menu to uppercase. It's easier to read and does the job and I personally prefer this method.
static void Main(string[] args)
{
string str1 = "Q";
string str2 = "q";
if (str1.Equals(str2, StringComparison.OrdinalIgnoreCase)) { }
string menu = "";
do
{
Console.WriteLine("Select Meun:(1)Triangle (2)Rectangle " +
"(Q)Quit",string.Equals
(str1, str2,
StringComparison.CurrentCultureIgnoreCase));
menu = Console.ReadLine();
Console.WriteLine(menu + "is selected");
} while (menu.ToUpper() != "Q");
}
Addtional
There's also the example below that uses switch statements which are great and easier to read if you plan on having a lot of options in the future:
do
{
Console.WriteLine("Select Menu:(1)Triangle (2)Rectangle (Q)Quit");
menu = Console.ReadLine();
switch (menu.ToUpper())
{
case "1":
//DO SOME CODE
break;
case "2":
//DO SOME CODE
break;
case "Q":
return;
}
Console.WriteLine(menu + " is selected");
} while (true);
Or this method which doesn't use any StringComparison or ToUpper and would be use if you would want separate upper and lower case commands, or if you dont want to do any additional conversion/checking.
do
{
Console.WriteLine("Select Menu:(1)Triangle (2)Rectangle (Q)Quit");
menu = Console.ReadLine();
switch (menu)
{
case "1":
//DO THIS
break;
case "2":
//DO THAT
break;
case "q":
case "Q":
return;
}
Console.WriteLine(menu + " is selected");
} while (true);
This is my class:
using System;
using System.Collections.Generic;
using System.Text;
namespace Num2Wrd
{
public class NumberToEnglish
{
public String changeNumericToWords(double numb)
{
String num = numb.ToString();
return changeToWords(num, false);
}
public String changeCurrencyToWords(String numb)
{
return changeToWords(numb, true);
}
public String changeNumericToWords(String numb)
{
return changeToWords(numb, false);
}
public String changeCurrencyToWords(double numb)
{
return changeToWords(numb.ToString(), true);
}
private String changeToWords(String numb, bool isCurrency)
{
String val = "", wholeNo = numb, points = "", andStr = "", pointStr = "";
String endStr = (isCurrency) ? ("Only") : ("");
try
{
int decimalPlace = numb.IndexOf(".");
if (decimalPlace > 0)
{
wholeNo = numb.Substring(0, decimalPlace);
points = numb.Substring(decimalPlace + 1);
if (Convert.ToInt32(points) > 0)
{
andStr = (isCurrency) ? ("and") : ("point");// just to separate whole numbers from points/Rupees
endStr = (isCurrency) ? ("Rupees " + endStr) : ("");
pointStr = translateRupees(points);
}
}
val = String.Format("{0} {1}{2} {3}", translateWholeNumber(wholeNo).Trim(), andStr, pointStr, endStr);
}
catch
{
;
}
return val;
}
private String translateWholeNumber(String number)
{
string word = "";
try
{
bool beginsZero = false;//tests for 0XX
bool isDone = false;//test if already translated
double dblAmt = (Convert.ToDouble(number));
//if ((dblAmt > 0) && number.StartsWith("0"))
if (dblAmt > 0)
{//test for zero or digit zero in a nuemric
beginsZero = number.StartsWith("0");
int numDigits = number.Length;
int pos = 0;//store digit grouping
String place = "";//digit grouping name:hundres,thousand,etc...
switch (numDigits)
{
case 1://ones' range
word = ones(number);
isDone = true;
break;
case 2://tens' range
word = tens(number);
isDone = true;
break;
case 3://hundreds' range
pos = (numDigits % 3) + 1;
place = " Hundred ";
break;
case 4://thousands' range
case 5:
case 6:
pos = (numDigits % 4) + 1;
place = " Thousand ";
break;
case 7://millions' range
case 8:
case 9:
pos = (numDigits % 7) + 1;
place = " Million ";
break;
case 10://Billions's range
pos = (numDigits % 10) + 1;
place = " Billion ";
break;
//add extra case options for anything above Billion...
default:
isDone = true;
break;
}
if (!isDone)
{//if transalation is not done, continue...(Recursion comes in now!!)
word = translateWholeNumber(number.Substring(0, pos)) + place + translateWholeNumber(number.Substring(pos));
//check for trailing zeros
if (beginsZero) word = " and " + word.Trim();
}
//ignore digit grouping names
if (word.Trim().Equals(place.Trim())) word = "";
}
}
catch
{
;
}
return word.Trim();
}
private String tens(String digit)
{
int digt = Convert.ToInt32(digit);
String name = null;
switch (digt)
{
case 10:
name = "Ten";
break;
case 11:
name = "Eleven";
break;
case 12:
name = "Twelve";
break;
case 13:
name = "Thirteen";
break;
case 14:
name = "Fourteen";
break;
case 15:
name = "Fifteen";
break;
case 16:
name = "Sixteen";
break;
case 17:
name = "Seventeen";
break;
case 18:
name = "Eighteen";
break;
case 19:
name = "Nineteen";
break;
case 20:
name = "Twenty";
break;
case 30:
name = "Thirty";
break;
case 40:
name = "Fourty";
break;
case 50:
name = "Fifty";
break;
case 60:
name = "Sixty";
break;
case 70:
name = "Seventy";
break;
case 80:
name = "Eighty";
break;
case 90:
name = "Ninety";
break;
default:
if (digt > 0)
{
name = tens(digit.Substring(0, 1) + "0") + " " + ones(digit.Substring(1));
}
break;
}
return name;
}
private String ones(String digit)
{
int digt = Convert.ToInt32(digit);
String name = "";
switch (digt)
{
case 1:
name = "One";
break;
case 2:
name = "Two";
break;
case 3:
name = "Three";
break;
case 4:
name = "Four";
break;
case 5:
name = "Five";
break;
case 6:
name = "Six";
break;
case 7:
name = "Seven";
break;
case 8:
name = "Eight";
break;
case 9:
name = "Nine";
break;
}
return name;
}
private String translateRupees(String Rupees)
{
String cts = "", digit = "", engOne = "";
for (int i = 0; i < Rupees.Length; i++)
{
digit = Rupees[i].ToString();
if (digit.Equals("0"))
{
engOne = "Zero";
}
else
{
engOne = ones(digit);
}
cts += " " + engOne;
}
return cts;
}
}
}
Form contains two Textboxes (textBox1 and textBox2) and a Button(button1).
I want to type an amount in numbers in textBox1 and click on the button. The amount entered in numbers in textBox1 has to be converted to text and appear in textbox2. Functions to convert are in above C# class file. I am a new student. Can anyone help me in solving this problem.
You have to create an object for 'NumberToEnglish' Class and use it in Form1.cs this way
public partial class Form1 : Form
{
NumberToEnglish neObj = new NumberToEnglish();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = neObj.changeCurrencyToWords(Convert.ToDouble(textBox1.Text));
}
}
public partial class Form1 : Form
{
NumberToEnglish Obj = new NumberToEnglish();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox2.Text = Obj.changeCurrencyToWords(textBox1.Text);//As your method accept a string..
}
}
This question already exists:
c# programming constructs - my while loop wont stop working when i want it to? [closed]
Closed 9 years ago.
i am trying to get my while loop to ONLY keep repeating till all subjects have been answered, then it should stop and display the bonus and final score. but don't know why its not doing that? help please.
namespace Assignment
{
class Class1
{
public static int attempt, sum, AptScore, GenScore, MathScore, EngScore, bonus, TotalScore, FinalScore, choice = 0;
public static string ans;
static void Main(string[] args)
{
bool stop = false;
Console.WriteLine("Welcome to this Salisbury University IQ Test game");
Console.WriteLine();
Console.WriteLine("How many times have you attempted this test?");
attempt = Convert.ToInt32(Console.ReadLine());
while (true)
if (attempt > 1)
{
Console.WriteLine("You cannot take this test");
}
else
{
Console.WriteLine(" \n1. Aptitude \n2. English. \n3. Math \n4. Gk \n5. Exit");
choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
Console.WriteLine(" What was the name of the lebanon tyrant who ruled for years unending before he was toppled due to civil war? \nA. Osama Bin laden \nB. Gaddafi \nC. Jonathan ");
ans = Console.ReadLine();
if (ans == "B" || ans == "b")
{
AptScore += 10;
}
break;
case 2:
Console.WriteLine(" What is the antonym of Pleasure? \nA. Pain \nB. Ecstacy \nC. Wonder");
ans = Console.ReadLine();
if (ans == "A" || ans == "a")
{
EngScore += 10;
}
break;
case 3:
Console.WriteLine(" What is the sum of 435 and 345? \nA. 799 \nB. 780 \nC. 600 ");
ans = Console.ReadLine();
if (ans == "B" || ans == "b")
{
MathScore += 10;
}
break;
case 4:
Console.WriteLine(" What year did Nigeria become a republic? \nA. 1960 \nB. 1963 \nC. 1990 ");
ans = Console.ReadLine();
if (ans == "B" || ans == "b")
{
GenScore += 10;
}
break;
case 5:
Environment.Exit(0);
break;
}
if (stop)
break;
TotalScore = MathScore + GenScore + EngScore + AptScore;
Console.WriteLine("Your total score is : " + TotalScore);
if (TotalScore == 10)
{
Console.WriteLine(" You have no Bonus point ");
}
else if (TotalScore == 20)
{
bonus += 2;
Console.WriteLine("Your Bonus is {0}", bonus);
}
else if (TotalScore == 30)
{
bonus += 5;
Console.WriteLine("Your Bonus is {0}", bonus);
}
else if (TotalScore == 40)
{
bonus += 10;
Console.WriteLine("Your Bonus is {0}", bonus);
}
else
{
FinalScore = TotalScore + bonus;
Console.WriteLine("Your finalscore is : " + FinalScore);
}
switch (FinalScore)
{
case 10:
if (FinalScore >= 10)
{
Console.WriteLine("Your IQ level is below average");
}
break;
case 22:
if (FinalScore >= 22)
{
Console.WriteLine("Your IQ level is average");
}
break;
case 35:
if (FinalScore >= 35)
{
Console.WriteLine("You are intelligent");
}
break;
case 40:
if (FinalScore == 40)
{
Console.WriteLine("You are a genius");
}
break;
default:
break;
}
}
}
}
}
if (stop)
break;
This never happens.
I see:
bool stop = false;
and also:
if (stop)
break;
But I never see a stop = true;
Where do you intend to set stop to true?