Skip to content

Instantly share code, notes, and snippets.

@karan-ta
Created September 6, 2020 06:10
Show Gist options
  • Save karan-ta/4f240c69063191b3d1370551255b4699 to your computer and use it in GitHub Desktop.
Save karan-ta/4f240c69063191b3d1370551255b4699 to your computer and use it in GitHub Desktop.
import 'dart:math';
import 'dart:io';
add (int first,int second,int playeranswer)
{
if (first + second == playeranswer)
{
print ("you got it!");
}
if (first + second != playeranswer)
{
print ("Better Luck next time!");
}
}
subtract (int first,int second, int playeranswer)
{
if (first - second == playeranswer)
{
print ("you got it!");
}
if (first - second != playeranswer)
{
print ("Better Luck next time!");
}
}
multiply (int first,int second,int playeranswer)
{
if (first * second == playeranswer)
{
print ("you got it!");
}
if (first * second != playeranswer)
{
print ("Better Luck next time!");
}
}
divide (int first,int second,int playeranswer)
{
if (first/second == playeranswer)
{
print ("you got it!");
}
if (first/second != playeranswer)
{
print ("Better Luck next time!");
}
}
main ()
{
print ("please enter + or - or * or /");
var playeroperation = stdin.readLineSync ();
print ("please enter easy or medium or hard level");
var level = stdin.readLineSync();
Random r = Random ();
var first;
var second;
if (level == "easy")
{
first = r.nextInt (1500);
second = r.nextInt (1000);
}
if (level == "medium")
{
first = r.nextInt (15000);
second = r.nextInt (10000);
}
if (level == "hard")
{
first = r.nextInt (150000);
second = r.nextInt (100000);
}
print (playeroperation);
print (first);
print (second);
var playeranswer = int.parse(stdin.readLineSync ());
if (playeroperation == "+")
{
add (first,second,playeranswer);
}
if (playeroperation == "-")
{
subtract (first,second,playeranswer);
}
if (playeroperation == "*")
{
multiply (first,second,playeranswer);
}
if (playeroperation == "/")
{
divide (first,second,playeranswer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment