
It looks like you're new here. If you want to get involved, click one of these buttons!
Hey everyone!
Here is my solution to the challenge from the C# Tutorial 03 (Conditions) video that is out soon.
Have fun with it! 😀
using System; namespace My_Awesome_Program { class Program { static void Main(string[] args) { int answer; // First problem Console.Write("15 + 2 * 2 = "); answer = Convert.ToInt32(Console.ReadLine()); if (answer == 60) { Console.WriteLine("Correct!"); } else { Console.WriteLine("Wrong!"); } // Second problem Console.Write("10 * 2 / 4 = "); answer = Convert.ToInt32(Console.ReadLine()); if (answer == 5) { Console.WriteLine("Correct!"); } else { Console.WriteLine("Wrong!"); } // Third problem Console.Write("(4 + 3 + 2 + 1) / 2 = "); answer = Convert.ToInt32(Console.ReadLine()); if (answer == 6) { Console.WriteLine("Correct!"); } else { Console.WriteLine("Wrong!"); } // Wait before closing Console.ReadKey(); } } }
Comments
i made this code in my phone to calculate the average.
using System;
namespace JAIVINs_PROGRAM
{
public static class Program
{
public static void Main()
{
double num02;
double num03;
double num01;
double average;
Console.WriteLine("This is a average calculator enter your number to prceed");
Console.Write("Enter the first number =>");
num01 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the second number =>");
num02 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the third number =>");
num03 = Convert.ToDouble(Console.ReadLine());
average = (num01 + num02 + num03) / 3;
Console.Write("This is the final result =>" + average );
Console.ReadKey();
}
}
}
My answer to the problem:
using System;
namespace VSCODEPROJ
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Math Challenge";
Console.WriteLine("1 x 5 + 2 x 5 = ?");
int firstResult = Convert.ToInt32( (Console.ReadLine() ));
if (firstResult == 15)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("Incorrect!");
}
Console.WriteLine("5 x 5 + 3 + 7 = ?");
int secondResult = Convert.ToInt32( (Console.ReadLine() ));
if (secondResult == 35)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("Incorrect!");
}
Console.WriteLine("Test finished. Press any key to continue...");
Console.ReadKey();
}
}
}
This is how I did it!
using System;
namespace Awesome_Program
{
class Program
{
static void Main(string[] args)
{
Console.Title = ("Maths Quiz");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine("What is 10 x 3?");
int q1 = Convert.ToInt32(Console.ReadLine());
if(q1 == 30) {
Console.WriteLine("Correct!");
}else {
Console.WriteLine("Incorrect!");
}
Console.WriteLine("Mass = 10kg, Acceleration = 10 metres per second find the force");
int q2 = Convert.ToInt32(Console.ReadLine());
if(q2 == 100) {
Console.WriteLine("Correct!");
}else {
Console.WriteLine("Incorrect!");
}
Console.WriteLine("What is 10 + 2 x 3?");
int q3 = Convert.ToInt32(Console.ReadLine());
if (q3 == 16) {
Console.WriteLine("Correct!");
}else {
Console.WriteLine("Incorrect!");
}
Console.WriteLine("What is 60 + 32");
int q4 = Convert.ToInt32(Console.ReadLine());
if (q4 == 92) {
Console.WriteLine("Correct!");
}else {
Console.WriteLine("Incorrect!");
}
Console.WriteLine("What is 100 x 2 + 8");
int q5 = Convert.ToInt32(Console.ReadLine());
if(q5 == 208) {
Console.WriteLine("Correct!");
}else{
Console.WriteLine("Incorrect!");
}
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("The quiz has been completed! Press any key to do it over!");
//Wait before closing
Console.ReadKey();
}
}
}
This is my solution(please tell me if there's anything I could do to improve it!):
easy
using System;
namespace My_First_Code
{
class Program
{
static void Main(string[] args)
{
int ans1;
int ans2;
int ans3;
Console.WriteLine("1+1= ");
ans1 = Convert.ToInt32(Console.ReadLine());
if (ans1 == 2)
{
Console.WriteLine("correct");
}
else
{
Console.WriteLine("wrong");
}
Console.WriteLine("2+2= ");
ans2 = Convert.ToInt32(Console.ReadLine());
if (ans2 == 4)
{
Console.WriteLine("correct");
}
else
{
Console.WriteLine("wrong");
}
Console.WriteLine("4+4= ");
ans3 = Convert.ToInt32(Console.ReadLine());
if (ans3 == 8)
{
Console.WriteLine("correct");
}
else
{
Console.WriteLine("wrong");
}
My answer to the problem :
using System;
namespace Math_Quiz
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Math Quiz";
int answer;
// First Question
Console.Write("5 * 3 = ");
answer = Convert.ToInt32(Console.ReadLine());
if (answer == 15) {
Console.WriteLine("Correct!");
} else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Incorrect!");
}
// Second Question
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("10 * 2 / 2 = ");
answer = Convert.ToInt32(Console.ReadLine());
if (answer == 10) {
Console.WriteLine("Correct!");
} else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Incorrect!");
}
// Third Question
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("30 + 15 + 5 = ");
answer = Convert.ToInt32(Console.ReadLine());
if (answer == 50) {
Console.WriteLine("Correct!");
} else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Incorrect!");
}
// wait before closing
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("***Press any key to exit***");
Console.ReadKey();
}
}
}
I am 12 years old and here's my program.
using System;
namespace Conditions
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Math test.";
int answer;
int correctAnswers = 0;
int wrongAnswers = 0;
Console.ForegroundColor = ConsoleColor.White;
Console.Write("1. (10 x 2) / 4? ");
answer = Convert.ToInt16(Console.ReadLine());
if (answer == 5)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Correct!");
correctAnswers += 1;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong!");
wrongAnswers += 1;
}
Console.ForegroundColor = ConsoleColor.White;
Console.Write("2. 150 x 5 - 10 / 2? ");
answer = Convert.ToInt16(Console.ReadLine());
if (answer == 370)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Correct!");
correctAnswers += 1;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong!");
wrongAnswers += 1;
}
Console.ForegroundColor = ConsoleColor.White;
Console.Write("9 + 1 * 16? ");
answer = Convert.ToInt16(Console.ReadLine());
if (answer == 26)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Correct!");
correctAnswers += 1;
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong!");
wrongAnswers += 1;
}
Console.WriteLine("You had " + correctAnswers + " correct answer(s) and " + wrongAnswers + " wrong answer(s).");
Console.ReadKey();
}
}
}
Hi Brackeys,
I am a huge fan of your's.
I am 14 years old and learned coding through your videos. Thanks for so much good content on your youtube channel.
I have uploaded a new code down please refer that.
Hello Brackeys, je suis 14 years old and i am not good in french.
using System;
namespace The_Test_Object
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
Console.Title = "Morning :)";
//points
int score = 3;
//problem 01
Console.WriteLine("What is the awnser to: 2 * 4 + 9 :"); //17
var awnser = Convert.ToDouble(Console.ReadLine());
if(awnser == 17){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Good Job");
}
else{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong");
score = score - 1;
}
Console.ForegroundColor = ConsoleColor.White;
//problem 02
Console.WriteLine("What is the awnser to: 90 - 18 / 3 :"); //15
awnser = Convert.ToDouble(Console.ReadLine());
if(awnser == 15){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Good Job");
}
else{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong");
score = score - 1;
}
Console.ForegroundColor = ConsoleColor.White;
//problem03
Console.WriteLine("What is the awnser to: ((29 - 9) / 2 ) * 3 :"); //30
awnser = Convert.ToDouble(Console.ReadLine());
if(awnser == 30){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Good Job");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Your Finale Score = " + score + "/3");
}
else{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong");
score = score - 1;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Your Finale Score = " + score + ("/3"));
}
Console.ForegroundColor = ConsoleColor.White;
//Close thingy
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("--Press a key to exit--");
Console.ReadKey();
}
}
}
Hi brackeys,
The code which I uploaded yersterday was not good. So here is the revamped version of the code-
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Math Problems";
int points = 3;
Console.WriteLine("Answer some simple math problems");
Console.Write("Question1. 2*8*2*8:");
int ans = Convert.ToInt32(Console.ReadLine());
if (ans == 256)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Correct");
if (ans != 256)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Oh no you answered wrong. Try again:");
points = points - 1;
int ty = Convert.ToInt32(Console.ReadLine());
if (ty != 256)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Oops you answered the question wrong again, you are out.");
}
else if (ty == 256)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("YAY the answer is right.");
}
}
Console.Write("First Question was easy. Now Question2.5*6*5*6-300:");
int ans1 = Convert.ToInt32(Console.ReadLine());
if (ans1 == 600)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("WOW, again a right answer.");
}
else if (ans1 != 600)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Oh no you answered the question wrong. Try again:");
points = points - 1;
int ty1 = Convert.ToInt32(Console.ReadLine());
if (ty1 != 600)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Oops you answered the question wrong again, you are out.");
}
else if (ty1 == 600)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("YAY you answered the question right.");
}
}
Console.WriteLine("I bet this will take some time");
Console.Write("256*256:");
int ans2 = Convert.ToInt32(Console.ReadLine());
if (ans2 == 65536)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("WOW you are really very smart.");
}
else if (ans2 != 65536)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Oh no you answered it wrong. Try again:");
points = points - 1;
int ty2 = Convert.ToInt32(Console.ReadLine());
if (ty2 != 65536)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Oops you answered the question wrong again, you are out.");
}
else if (ty2 == 65536)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("YAY you answered the question right.");
}
}
}
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("YAY, you attemped all the problems and your total points were:" + points + "/3.");
Console.ReadLine();
}
}
}
//Hi Brackeys. I have added a simple grading system using Switch-Case. Here is the code-
using System;
namespace Awesome_Projects
{
class Program
{
static void Main(string[] args)
{
Console.Title = "FRIDAY";
int score = 0;
// QUESTION 1
Console.WriteLine("Welcome to the MATH QUIZ. \nHere is your First problem");
Console.Write("10+20 = ");
int result1 = Convert.ToInt32(Console.ReadLine());
if(result1 == 30){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Correct");
score++;
}else{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong");
}
// QUESTION 2
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Here is your Second problem");
Console.Write("999*999 = ");
int result2 = Convert.ToInt32(Console.ReadLine());
if(result2 == 998001){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Correct");
score++;
}else{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong");
}
// QUESTION 3
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Here is your Third problem");
Console.Write("(4+3+2+1)/2 = ");
int result3 = Convert.ToInt32(Console.ReadLine());
if(result3 == 5){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Correct");
score++;
}else{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong");
}
// QUESTION 4
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Here is your Fourh problem");
Console.Write("2/2 = ");
int result4 = Convert.ToInt32(Console.ReadLine());
if(result4 == 1){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Correct");
score++;
}else{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong");
}
// QUESTION 5
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Here is your Fifth problem");
Console.Write("128*789*548*0*896*999 = ");
int result5 = Convert.ToInt32(Console.ReadLine());
if(result5 == 0){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Correct");
score++;
}else{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Wrong");
}
//SCORE COUNT & GRADING
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Your final score is: " + score);
Console.WriteLine("Your grade is");
switch(score){
case 0:
Console.WriteLine("F");
break;
case 1:
Console.WriteLine("D");
break;
case 2:
Console.WriteLine("C");
break;
case 3:
Console.WriteLine("B");
break;
case 4:
Console.WriteLine("A");
break;
case 5:
Console.WriteLine("A+");
break;
default:
Console.WriteLine("Default");
break;
}
Console.ReadKey();
}
}
}
Here's my solution :)
Here's my solution :
using System;
namespace Episode_3_qus
{
class Program
{
static void Main(string[] args)
{
int correct = 0;
int worng = 0;
Console.WriteLine("Here's a question: 15 * 2 + 10 = ?");
Console.WriteLine("You have 4 options:");
Console.WriteLine("1. 40 2. 25");
Console.WriteLine("3. 30 4. 50");
Console.Write("Your choose is: ");
int choose;
choose = Convert.ToInt32(Console.ReadLine());
if (choose == 1)
{
Console.WriteLine("Correct!");
correct++;
}
else
{
Console.WriteLine("You worng!");
worng++;
}
Console.WriteLine("Here's a question: 19 * 2 + 15 = ?");
Console.WriteLine("You have 4 options:");
Console.WriteLine("1. -6 2. 100");
Console.WriteLine("3. 53 4. 77");
Console.Write("Your choose is: ");
choose = Convert.ToInt32(Console.ReadLine());
if (choose == 3)
{
Console.WriteLine("Correct!");
correct++;
}
else
{
Console.WriteLine("You worng!");
worng++;
}
Console.WriteLine("Here's a question: 100 * 2 + 2 = ?");
Console.WriteLine("You have 4 options:");
Console.WriteLine("1. 203 2. 202");
Console.WriteLine("3. 200 4. 254");
Console.Write("Your choose is: ");
choose = Convert.ToInt32(Console.ReadLine());
if (choose == 2)
{
Console.WriteLine("Correct!");
correct++;
}
else
{
Console.WriteLine("You worng!");
worng++;
}
Console.WriteLine("\n");
Console.WriteLine("You answered " + correct + " questions correctly");
Console.WriteLine("You made a mistake in " + worng + " questions");
}
}
}
Hi! If someone wanna execute this program. Do it and let me know how you like it.
Hi here is my answer to your challenge :D
using System;
namespace Math
{
class Program
{
static void Main(string[] args)
{
double result;
double answer;
//Welcom thing:)
Console.WriteLine("Wellcom to the hardest game of all time");
Console.WriteLine("What is 234 x 23");
//the condition thing
result = Convert.ToDouble(Console.ReadLine());
answer = 234 * 23;
if (result == answer)
{ Console.WriteLine("Congratulation!!");
}
else if (result != answer)
{Console.WriteLine("wrong");
}
Console.WriteLine("What is 25 x 2");
result = Convert.ToDouble(Console.ReadLine());
if (result == 50){
Console.WriteLine("Congratulation");
}
else if (result != 50)
{Console.WriteLine("Wrong");
}
Console.WriteLine("What is 23 x 34");
answer = 23 * 34;
result = Convert.ToDouble(Console.ReadLine());
if (result == answer)
{ Console.WriteLine("Congratulation!!");
}
else if (result != answer)
{Console.WriteLine("wrong");
Console.WriteLine("What is 200 : 2");
answer = 200 / 2;
result = Convert.ToDouble(Console.ReadLine());
if (result == answer)
{
Console.WriteLine("Congratulation");
}
else if (result != answer)
{
Console.WriteLine("wrong");
}
Console.WriteLine("What is 191 : 91");
answer = 191 / 91;
result = Convert.ToDouble( Console.ReadLine());
if (result == answer)
{
Console.WriteLine("Congratulation");
}
else if (result != answer)
{
Console.WriteLine("wrong");
}
Console.WriteLine("What is 200 : 20?");
answer = 200 / 20;
result = Convert.ToDouble( Console.ReadLine());
if (result == answer)
{
Console.WriteLine("Congratulation");
}
else if (result != answer)
{
Console.WriteLine("wrong");
}
Console.WriteLine("What is 392 : 131");
answer = 392 / 131;
result = Convert.ToDouble( Console.ReadLine());
if (result == answer)
{
Console.WriteLine("Congratulation");
}
else if (result != answer)
{
Console.WriteLine("wrong");
}
Console.WriteLine("What is 392 : 32");
answer = 392 / 32;
if (result == answer)
{
Console.WriteLine("Congratulation");
}
else if (result != answer)
{
Console.WriteLine("wrong");
}
Console.WriteLine("What is 392 : 36");
answer = 392 / 36;
if (result == answer)
{
Console.WriteLine("Congratulation");
}
else if (result != answer)
{
Console.WriteLine("Well,you done all :)");
Console.ReadKey();
}
}
}}}
}
HERES MINE BOIS!!!
using System;
namespace Conditions
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.DarkGreen;
int answer_1;
int answer_2;
Console.Write("1 * 87 = ");
answer_1 = Convert.ToInt32(Console.ReadLine());
if(answer_1 == 87)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("Wrong!");
}
Console.Write("30 / 2 = ");
answer_2 = Convert.ToInt32(Console.ReadLine());
if(answer_2 == 15)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("Wrong!");
}
if(answer_1 == 87 && answer_2 == 15)
{
Console.WriteLine(" \nYou Win!");
}
else if(answer_1 == 87 || answer_2 == 15)
{
Console.WriteLine(" \n1/2 Completed!");
}
else
{
Console.WriteLine(" \nYou Failed!");
}
// wait before closing
Console.ReadKey();
}
}
}
found the maths easy so i did a story quest like thing and i enjoyed makeing it alot i enjoy when i learn the code and i make code my self and it works out:)
-----------------------------------------
using System;
namespace C__quize
{
class Program
{
static void Main(string[] args)
{
Console.Write("your in the woods there are 3 paths to exit which do you take. ");
int path = Convert.ToInt32(Console.ReadLine());
switch (path)
{
case 1:
Console.Write("DEAD.");
break;
case 2:
Console.Write("you came second and there are 2 more paths which do you take. ");
int paths = Convert.ToInt32(Console.ReadLine());
switch (paths)
{
case 1:
Console.Write("DEAD.");
break;
case 2:
Console.Write("you have exited the woods you wake up and realised your in a simulation and you wonder to your self what is real and you decide to kill your self but instead of dying you forget everthing and get sent back to the woods.");
break;
default:
Console.Write("Thats not a option. ");
break;
}
break;
case 3:
Console.Write("you find a hut and you decide to live there until your old and dead but you soon go crazy and hang your self.The END");
break;
default:
Console.Write("you have exited the woods and you live on your boring ass life knowing thats the most fun you've had.The END");
break;
}
// wait before closing
Console.ReadKey();
}
}
}
MY SOLUTION HOPE YOU LIKE IT :)
I EVEN ADDED GREEN COLOR FOR CORRECT ANSWERS AND RED COLOR FOR WRONG ANSWERS
using System;
class HelloWorld {
static void Main() {
Console.Title = "math questions";
int answer;
Console.Write("Hello\nwhat is 50*20*132: ");
answer = Convert.ToInt32(Console.ReadLine());
if (answer == 132000 ){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("correct!");
} else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("wrong!");
}
Console.ForegroundColor = ConsoleColor.White;
int answer2;
Console.Write("what is (5*190*2)/2: ");
answer2 = Convert.ToInt32(Console.ReadLine());
if (answer2 == 950){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("correct!");
} else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("wrong!");
}
}
}
This is my first time using if statement in C#
and....... i think i can understand it pretty well
Still an absolutely beginner !
here is my answer :
------------------------------------------------------
using System;
namespace MyAwesomeMathQuiz
{
class Program
{
static void Main(string[] args)
{
int A1;
int A2;
int A3;
Console.Write("A1 : 4 * 6 + 5? ");
A1 = Convert.ToInt32(Console.ReadLine());
Console.Write("A2 : 9 * 5- 3? ");
A2 = Convert.ToInt32(Console.ReadLine());
Console.Write("A3 : 10 / 5 * 2? ");
A3 = Convert.ToInt32(Console.ReadLine());
if(A1 == 29)
{
Console.WriteLine("A1 Correct!");
} else {
Console.WriteLine("A1 Wrong!");
}
if(A2 == 42) {
Console.WriteLine("A2 Correct!");
} else {
Console.WriteLine("A2 Wrong!");
}
if(A3 == 4) {
Console.WriteLine("A3 Correct!");
} else {
Console.WriteLine("A3 Wrong!");
}
Console.ReadKey();
}
}
}
My answer :DDD
using System;
namespace Best_Program
{
class Program
{
static void Main(string[] args)
{
double answer;
Console.Write("1 + 2 + 2 = ");
answer = Convert.ToDouble(Console.ReadLine());
if (answer == 5)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("False!");
}
Console.Write("5 * 5 + 5 = ");
answer = Convert.ToDouble(Console.ReadLine());
if (answer == 30)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("False!");
}
Console.Write("10 * 11 + 50 = ");
answer = Convert.ToDouble(Console.ReadLine());
if (answer == 160)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("False!");
}
//10 * 2 + 3 = ?
Console.ReadKey();
}
}
}
using System;
namespace apprentissage_c__challenge_3
{
class Program
{
static void Main(string[] args)
{
int res01;
int res02;
int res03;
int res04;
int res05;
Console.Title = "challenge number 03";
Console.WindowHeight = 35;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Hello friend, we are going to play a game.\ni put equations and you find the correct answer.\nit's easy ? ok let's go !");
Console.WriteLine("15+8/2");
Console.ForegroundColor = ConsoleColor.White;
res01 = Convert.ToInt32 ( Console.ReadLine() );
if (res01 == 19)
{
Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("you got the right answer !");
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("No, bad answer, you dumb idiot !");
}
Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("12+3*2-1");
Console.ForegroundColor = ConsoleColor.White;
res02 = Convert.ToInt32 ( Console.ReadLine() );
if (res02 == 17)
{
Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("you got the right answer !");
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("No, bad answer, you dumb idiot !");
}
Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("3^3+2");
Console.ForegroundColor = ConsoleColor.White;
res03 = Convert.ToInt32 ( Console.ReadLine() );
if (res03 == 29)
{
Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("you got the right answer !");
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("No, bad answer, you dumb idiot !");
}
Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("1+1");
Console.ForegroundColor = ConsoleColor.White;
res04 = Convert.ToInt32 ( Console.ReadLine() );
if (res04 == 2)
{
Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("you got the right answer !");
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("No, bad answer, you dumb idiot !");
}
Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("987+654+321");
Console.ForegroundColor = ConsoleColor.White;
res05 = Convert.ToInt32 ( Console.ReadLine() );
if (res05 == 1962)
{
Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine("you got the right answer !");
}
else
{
Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("No, bad answer, you dumb idiot !");
}
if (res01 == 19 && res02 == 17 && res03 == 29 && res04 == 2 && res05 == 1962 )
{
Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nall your answers were right, congratulations !");
}
else if (res01 != 19 && res02 != 17 && res03 != 29 && res04 != 2 && res05 != 1962)
{
Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nsorry, all your answers were wrong, try harder next time !");
}
else
{
Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nsome of your answers were wrong, try to get them all right next time !");
}
Console.ReadKey();
}
}
}
i did a shorter one, because the first one was too long
This is my solution, but i didn't use curly brackets for the if and else statements.
And it is still correct, Why is this.
Console.WriteLine(" 12 * 5 / 6 =");
int answer = Convert.ToInt32(Console.ReadLine());
if (answer == 10)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("Incorrect");
}
Console.WriteLine(" 12 * 5 /20 =");
int answer2 = Convert.ToInt32(Console.ReadLine());
if (answer2 == 3)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("Incorrect");
}
Console.WriteLine(" 12 * 5 /3 =");
int answer3 = Convert.ToInt32(Console.ReadLine());
if (answer3 == 20)
{
Console.WriteLine("Correct!");
}
else
{
Console.WriteLine("Incorrect");
}
I made this a bit too complicated. For some reason, I was thinking that they needed to get the first one correct to get the next one to show up. Silly me.