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

Updated on May 14, 2018 in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
11 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 on December 14, 2017

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! (ง •_•)ง

on December 14, 2017

why my codes are all mess…

Guru
on December 14, 2017

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

 

Show more replies
  • Liked by
Reply
Cancel
0 on January 2, 2018
//The Instructions
 Console.WriteLine("The rule is simple!" +
 "\n\nAfter you hit Enter you will be able to see two numbers!" +
 "\nThen hit Enter again and do what the console tells you!" +
 "\n\nTo restart the process, hit Enter.\n");
 Console.ReadKey();
//The new entry point, when you hit enter at the end of the programm
 Start:
 //The numbers
 int n1 = 100;
 int n2 = 50;
 Console.WriteLine("Number 1: {0}", n1);
 Console.WriteLine("Number 2: {0}\n",n2);
 Console.ReadKey();
//The challenge
 Console.WriteLine("{0} + {1} equals?\n", n1, n2);
 int entrynumber = Convert.ToInt32(Console.ReadLine());
// When the solution is wrong you'll get a different text, to the right answer
 if (entrynumber == 150)
 {
 Console.WriteLine("Great that's right!\n\n\n");
 } else if(entrynumber != 150 )
 {
 Console.WriteLine("Maybe you should check your answer!\n\n\n");
 }
Console.ReadKey();
goto Start;
  • Liked by
Reply
Cancel
0 on May 14, 2018

why is this not working?

using System;

namespace FirstConsoleProject
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Random random = new Random ();
            int num01 = random.Next(1, 11);
            int num02 = random.Next(1, 11);
            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 {
                int responceIndex = random.Next(1,4)
                    
                    switch (responceIndex){
                case 1 :
                    Console.WriteLine (“Are you even trying?“);
                    break;
                }
                {
                case 2 :
                    Console.WriteLine (“Your answer is incorrect.“);
                    break;
                }
                {
                default:
                    Console.WriteLine (“You can do better than that.“);
                    break;
                }
            }
        Console.ReadKey ();
    }
}

  • Liked by
Reply
Cancel