0
Alright I have a situation...
So, I have been working on something and it’s not working out well. So, I need your help int money = 500; int a = 100; int b = 100; int c = 100; int d = 100; int e = 100; string monkey = "Bananas"; Console.WriteLine("What do monkeys eat? "); string answer = Console.ReadLine(); if (answer == monkey) { Console.WriteLine(monkey); Console.WriteLine("Congrats"); Console.WriteLine(money + a); if (answer != monkey) { Console.WriteLine(answer); Console.WriteLine("Nope,sorry"); Console.WriteLine(money - b); Can you tell me what’s wrong?
8 odpowiedzi
+ 2
1. Don't you think a, b...e variables are useless ? Not only do they have the same exact value, but you don't even change it, so just add 100 and substract it directly.
2. Same thing goes for the string monkey, just test with answer == "Bananas"
3. Why use if the second time ? There is a reason else statement exist.
4. "It's not working out" doesn't give us any hints on whhat or where the problem is, at least say what was the error and to which line it pointed.
+ 2
embed your situation in a code and insert the link 🔗 don't populate the q/a forum 😉
+ 1
ElijahCombs23 you didn't close the if statement, you should add } before the second if (and make the second if an else)
0
I did try the else statement. And thanks.
0
ok, I got ya, now.
0
Aymane Boukrouh [Unavailable] here’s how it turned out.... int money = 500;
string monkey = "Bananas";
Console.WriteLine("What do monkeys eat? ");
string answer = Console.ReadLine();
if (answer == "Bananas") {
Console.WriteLine(monkey);
Console.WriteLine("Awesome!");
Console.WriteLine(money + 100);
} else {
Console.WriteLine(answer);
Console.WriteLine("Nope, sorry!");
Console.WriteLine(money - 100);
}
0
ElijahCombs23 try to make a proper indentation, it makes it makes it look better, and more readable