Answer to the Challenge in How to program in C# nr. 4

Updated 10 hours ago in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
8 on September 14, 2014

So here is my answer to the challenge I gave you in How to program in C# nr. 4. I’m posting it here so those of you who couldn’t get it to work can see one possible way of doing it. Also, I’m planning to expand on this code in video nr. 5 so you can just copy/paste from here when the video comes out (currently working on it). Enjoy 🙂


using System;
namespace FirstConsoleProject

{

class MainClass

{

public static void Main (string[] args) // this is a method called "Main". It is called when the program starts.

{

int num01 = 16;

int num02 = 4;
Console.WriteLine ("What is " + num01 + " times " + num02 + "?");
int answer = Convert.ToInt32 (Console.ReadLine ());
if (answer == num01 * num02) {

Console.WriteLine ("Well done! Your answer is correct.");

} else {

Console.WriteLine ("Are you even trying?");

}
Console.ReadKey();

}

}

}

  • Liked by
  • Marlowe
  • Ajbaluch
  • Skyscope
  • Gabester
  • Wolf_MCS
  • +3
Reply
2 on May 13, 2015

Can i somehow make the numbers random ?

on May 14, 2015
on May 17, 2015

I googled it then try to make my program. And then I go to the next tutorial and saw he used that in the tutorial 😀 
But still thx for trying to help me :))

Show more replies
  • Liked by
Reply
Cancel
0 on May 15, 2017

Hello, guys, I am a 3D game Artist I have no knowledge of game development and I want to be an indie game developer so this course will help me? My target is to learn C# Basic and then move to Unity development what you say guys I am on right track or what?

  • Liked by
Reply
Cancel
0 on September 28, 2017

the answer for this is revealed in ep5. also in Tutorial#5 Brackeys says you can make the game restart but when I try this using (Start:/goto Start;), the game restarts and always has the same question even though I have the RNG properly configurated. how can I make the game give new numbers without closing and opening the game?

edit: I figured it out. the Start: had to be before the RNG code. sorry, feel free to delete this post or tell me how to.

  • Liked by
Reply
Cancel
2 10 hours ago

this my homework……  I’m a Chinese,English writing is not very well,some English grammar may be wrong,U•ェ•*U

This is my idea,  and then I wrote the following program。 

  • If the user enter the wrong answer, press Enter, the console will appear “oh, You better try again.”, Then the user press Enter, then he can re-enter the answer, until the answer is correct.
    If the user input the correct answer, press Enter, the console will appear “That’s true.” Then the user press Enter, the program will directly exit.

 

//设想的解决办法<1> using System; namespace MathProblemHomeWork { class MainClass { public static void Main(string[] args)   { var num01 = 10; var num02 = 5; Console.WriteLine("This is a math problem. Type spacebar to continue."); Console.ReadKey(); start: Console.WriteLine(num01 + " Divided by " + num02 + " is equal to: ");   int answer = Convert.ToInt32(Console.ReadLine()); if (answer == 2) { Console.WriteLine("That's true."); } else { Console.WriteLine("oh,You better try again."); goto start; } Console.ReadKey (); } } }

 

After this, I watch the next tutorial, then I find the if (answer == 2)  phase is wrong , opps! (ง •_•)ง

10 hours ago

why my codes are all mess…

Guru
10 hours ago

That’s because of the forum, I fixed it for you 🙂

 

Show more replies
  • Liked by
Reply
Cancel