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?

21st Nov 2019, 6:55 AM
ElijahCombs23
ElijahCombs23 - avatar
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.
21st Nov 2019, 7:01 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
embed your situation in a code and insert the link 🔗 don't populate the q/a forum 😉
21st Nov 2019, 2:52 PM
Aditya
Aditya - avatar
+ 1
ElijahCombs23 you didn't close the if statement, you should add } before the second if (and make the second if an else)
21st Nov 2019, 7:04 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
0
I did try the else statement. And thanks.
21st Nov 2019, 7:03 AM
ElijahCombs23
ElijahCombs23 - avatar
0
ok, I got ya, now.
21st Nov 2019, 7:05 AM
ElijahCombs23
ElijahCombs23 - avatar
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); }
21st Nov 2019, 7:43 AM
ElijahCombs23
ElijahCombs23 - avatar
0
ElijahCombs23 try to make a proper indentation, it makes it makes it look better, and more readable
21st Nov 2019, 12:10 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
21st Nov 2019, 12:16 PM
ElijahCombs23
ElijahCombs23 - avatar