Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.Write("what is your name?");
			string name = Console.ReadLine();
			Console.WriteLine("what is your age?");
			try
			{
				int age = Convert.ToInt32(Console.ReadLine());
				if (age == 13)
				{
					Console.WriteLine("I am " + age.ToString() + " too!");
					Console.WriteLine("how are you?");
					string mood = Convert.ToString(Console.ReadLine());
					Console.WriteLine("So you're" + age + ". and your name is " + name + ". and you're current mood is " + mood + "? \n <yes or="">");
					string yesno = Console.ReadLine();
					if (yesno.ToLower() == "yes")
					{
						Console.WriteLine("Cool...");
						Console.WriteLine("let's do some maths.");
						Random numberGenerator = new Random();
						int num01 = numberGenerator.Next(1, 11);
						int num02 = numberGenerator.Next(1, 11);
						Console.WriteLine("What is " + num01 + " times " + num02 + " ?");
						int answer = Convert.ToInt32(Console.ReadLine());
						if (answer == num01 * num02)
						{
							Console.WriteLine("Well done you know what " + num01 + " times " + num02 + " is! Congrats");
							Console.WriteLine("<press the="" anykey="" to="" continue="">");
							Console.ReadKey();
							Console.WriteLine("Lets so some more...");

							Random numberGenerator1 = new Random();
							int num03 = numberGenerator1.Next(11, 31);
							int num04 = numberGenerator1.Next(11, 31);
							Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
							int answer1 = Convert.ToInt32(Console.ReadLine());
							if (answer1 == num03 * num04)
							{
								Console.WriteLine("Well done you know what " + num03 + " times " + num04 + " is! Congrats");
								Console.WriteLine("<press the="" anykey="" to="" continue="">");
								Console.ReadKey();
								Console.WriteLine("Lets so some more...");
						}
						else
						{
							Console.WriteLine("Go gack to school");
							Console.WriteLine("<press the="" anykey="" to="" continue="">");
							Console.ReadLine();
								Random numberGenerator2 = new Random();
								int num05 = numberGenerator1.Next(11, 31);
								int num06 = numberGenerator1.Next(11, 31);
								Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
								int answer2 = Convert.ToInt32(Console.ReadLine());
								if (answer2 == num05 * num06)
								{
									Console.WriteLine("Well done you know what " + num05 + " times " + num06 + " is! Congrats");
									Console.WriteLine("<press the="" anykey="" to="" continue="">");
									Console.ReadKey();
									Console.WriteLine("Lets so some more...");
						}
					}
					else
					{

						Console.WriteLine("You lied to me...");
						Console.WriteLine("<press the="" any="" key="" to="" exit="">");
						Console.ReadKey();
					}
				}
				else
				{
					Console.WriteLine("I am 13");
					Console.WriteLine("how are you?");
					string mood = Convert.ToString(Console.ReadLine());
					Console.WriteLine("So you're " + age + ". and your name is " + name + ". and you're current mood is " + mood + "? \n <yes or="">");
					string yesno = Convert.ToString(Console.ReadLine());
					if (yesno.ToLower() == "yes")
					{
						Console.WriteLine("Cool...");
						Console.WriteLine("let's do some maths.");
						Random numberGenerator = new Random();
						int num01 = numberGenerator.Next(1,11);
						int num02 = numberGenerator.Next(1, 11);
						Console.WriteLine("What is " + num01 + " times " + num02 + " ?");
						int answer = Convert.ToInt32(Console.ReadLine());
						if (answer == num01 * num02)
						{
							Console.WriteLine("Well done you know what " + num01 + " times " + num02 + " is! Congrats");
						}
						else
						{
							Console.WriteLine("Go gack to school");
							Console.WriteLine("<press the="" any="" key="" to="" exit.="">");
							Console.ReadLine();
						}
						Console.WriteLine("<press the="" any="" key="" to="" exit="">");
						Console.ReadKey();
					}
					else
					{

						Console.WriteLine("You lied to me...");
						Console.WriteLine("<press the="" any="" key="" to="" exit="">");
						Console.ReadKey();
					}
				}
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
				Console.WriteLine("You should have entered a number - go back to school...");		
				Console.WriteLine("<press the="" any="" key="" to="" exit="">");
				Console.ReadKey();
			}
		}
	}
}
Posted
Updated 11-Sep-15 10:12am
v3
Comments
Gaurav B Sinha 11-Sep-15 16:23pm    
Although its a nice attempt to learn programming, few suggestions which were missing in ur code block:
1. Naming conventions. Kindly refer C# programming conventions on Microsoft site.
2. Use of same local variables.
3. Try dividing your logic into small methods rather writing complete code block in one method.
4. Provide proper comments.
5. Don't write your logic in Main Block itself. Create methods and write your logic there. Happy Coding

It's simple enough really. You have mismatched { and } somewhere. Though, in the way you posted your code, it's pretty much impossible for anyone to tell where because it's not formatted properly.

EDIT
------------------------------
Now that it is formatted properly, two of your if statements are missing closing } characters.

Also, to make debugging and following this code easier, break this code out into multiple methods at each step in your "conversation" with the user.
 
Share this answer
 
v2
Comments
[no name] 11-Sep-15 16:14pm    
A 5 for this. But assuming OP is realy 13...(?) I would foregive that :)
Dave Kreskowiak 11-Sep-15 16:22pm    
The question was locked for editing for 10 minutes when I looked at it and there were no PRE tags around the code, so that's the best answer I could give at the time.
[no name] 11-Sep-15 16:51pm    
stop stop. it was not my intention to attack you and also not to criticize your answer in any point...why you think a vote a 5?
sorry...maybe my english is the weak point :(
Dave Kreskowiak 11-Sep-15 18:18pm    
I took no offense at all.
The
if (answer2 == num05 * num06)
below seems to be missing closng brace.

C#
else
						{
							Console.WriteLine("Go gack to school");
							Console.WriteLine("<press the="" anykey="" to="" continue="">");
							Console.ReadLine();
								Random numberGenerator2 = new Random();
								int num05 = numberGenerator1.Next(11, 31);
								int num06 = numberGenerator1.Next(11, 31);
								Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
								int answer2 = Convert.ToInt32(Console.ReadLine());
								if (answer2 == num05 * num06)
								{
									Console.WriteLine("Well done you know what " + num05 + " times " + num06 + " is! Congrats");
									Console.WriteLine("<press the="" anykey="" to="" continue="">");
									Console.ReadKey();
									Console.WriteLine("Lets so some more...");
						}
					}
 
Share this answer
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("what is your name?");
            string name = Console.ReadLine();
            Console.WriteLine("what is your age?");
            try
            {
                int age = Convert.ToInt32(Console.ReadLine());
                if (age == 13)
                {
                    Console.WriteLine("I am " + age.ToString() + " too!");
                    Console.WriteLine("how are you?");
                    string mood = Convert.ToString(Console.ReadLine());
                    Console.WriteLine("So you're" + age + ". and your name is " + name + ". and you're current mood is " + mood + "? \n ");
                    string yesno = Console.ReadLine();
                    if (yesno.ToLower() == "yes")
                    {
                        Console.WriteLine("Cool...");
                        Console.WriteLine("let's do some maths.");
                        Random numberGenerator = new Random();
                        int num01 = numberGenerator.Next(1, 11);
                        int num02 = numberGenerator.Next(1, 11);
                        Console.WriteLine("What is " + num01 + " times " + num02 + " ?");
                        int answer = Convert.ToInt32(Console.ReadLine());
                        if (answer == num01 * num02)
                        {
                            Console.WriteLine("Well done you know what " + num01 + " times " + num02 + " is! Congrats");
                            Console.WriteLine("");
                            Console.ReadKey();
                            Console.WriteLine("Lets so some more...");
                            Random numberGenerator1 = new Random();
                            int num03 = numberGenerator1.Next(11, 31);
                            int num04 = numberGenerator1.Next(11, 31);
                            Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
                            int answer1 = Convert.ToInt32(Console.ReadLine());
                            if (answer1 == num03 * num04)
                            {
                                Console.WriteLine("Well done you know what " + num03 + " times " + num04 + " is! Congrats");
                                Console.WriteLine(""); Console.ReadKey(); Console.WriteLine("Lets so some more...");
                            }
                            else
                            {
                                Console.WriteLine("Go gack to school");
                                Console.WriteLine(""); Console.ReadLine();
                                Random numberGenerator2 = new Random();
                                int num05 = numberGenerator1.Next(11, 31);
                                int num06 = numberGenerator1.Next(11, 31);
                                Console.WriteLine("What is " + num03 + " times " + num04 + " ?");
                                int answer2 = Convert.ToInt32(Console.ReadLine());
                                if (answer2 == num05 * num06)
                                {
                                    Console.WriteLine("Well done you know what " + num05 + " times " + num06 + " is! Congrats");
                                    Console.WriteLine(""); Console.ReadKey(); Console.WriteLine("Lets so some more...");
                                }
                                else
                                {
                                    Console.WriteLine("You lied to me...");
                                    Console.WriteLine("");
                                    Console.ReadKey();
                                }
                            }

                        }
                        else
                        {
                            Console.WriteLine("I am 13");
                            Console.WriteLine("how are you?");
                            string mood1= Convert.ToString(Console.ReadLine());
                            Console.WriteLine("So you're " + age + ". and your name is " + name + ". and you're current mood is " + mood + "? \n ");
                            string yesno1 = Convert.ToString(Console.ReadLine());
                            if (yesno1.ToLower() == "yes")
                            {
                                Console.WriteLine("Cool...");
                                Console.WriteLine("let's do some maths."); Random numberGenerator1 = new Random(); int num011 = numberGenerator1.Next(1, 11); int num021 = numberGenerator1.Next(1, 11);
                                Console.WriteLine("What is " + num01 + " times " + num021 + " ?");
                                int answer1 = Convert.ToInt32(Console.ReadLine());
                                if (answer1 == num01 * num021)
                                {
                                    Console.WriteLine("Well done you know what " + num01 + " times " + num021 + " is! Congrats");
                                }
                                else
                                {
                                    Console.WriteLine("Go gack to school"); Console.WriteLine(""); Console.ReadLine();
                                }
                                Console.WriteLine(""); Console.ReadKey();
                            }
                            else
                            {
                                Console.WriteLine("You lied to me...");
                                Console.WriteLine("");
                                Console.ReadKey();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("You should have entered a number - go back to school...");
                Console.WriteLine("");
                Console.ReadKey();
            }
        }
    }
}
 
Share this answer
 
v3
Comments
Patrice T 11-Sep-15 16:34pm    
Try to write a couple sentences to explain what is your solution !
Gaurav B Sinha 11-Sep-15 17:04pm    
Code block error removed. Local variables renamed as same name variables were being used in local scope. Extra Comments updated in question section.
Patrice T 11-Sep-15 17:10pm    
In you solution!
Use Improve solution to do it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900