So eto na yung sinasabi ko, busy sa work, halos wala ng oras magaral mag code, 1hr per day lang ako nakakabasa ng tutorial at sabay code na rin, mahirap kasi gigising ako ng maaga kahit madaling araw na uwi ko, pero tuloy tuloy lang walang araw na hindi ako nagbasa ng ebook at nginstall din ako ng excercise app sa phone ko more on console problems lang tulad ng basic input output, data types at if statement, tas konting looping, so far nasa topic ako na gagawa ng calculator sa console, na code ko mismo, walang ni anung video tutorial, code ako ng base sa nalaman ko at search sa google ng mga naencounter ko na problem,. eto yung code ko sa simple calculator,
sa mga marunong mag code jan sa c#, advise naman, working yung code ko pero alam ko ng maraming mali pagdating sa flow, pero nagwork sya sa gusto kong mangyari. check nyo na lang din po, napakasaya ko ng magawa ko to kasi from scratch ko to ginawa,.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
string operation = "";
string again = "yes";
if (again == "yes")
{
do
{
Console.Write("What type of calculation do you want? ( *, /, + or - )");
operation = Console.ReadLine();
if (operation == "*")
{
Multiply();
Console.WriteLine("\nWrite 'yes' to restart application \nAnd press any key to quit");
string ans = Console.ReadLine();
if (ans != "yes")
{
Console.WriteLine("Thank you!");
break;
}
}
else if (operation == "/")
{
Divide();
Console.WriteLine("\nWrite 'yes' to restart application \nAnd press any key to quit");
string ans = Console.ReadLine();
if (ans != "yes")
{
Console.WriteLine("Thank you!");
break;
}
}
else if (operation == "+")
{
Add();
Console.WriteLine("\nWrite 'yes' to restart application \nAnd press any key to quit");
string ans = Console.ReadLine();
if (ans != "yes")
{
Console.WriteLine("Thank you!");
break;
}
}
else if (operation == "-")
{
Subtract();
Console.WriteLine("\nWrite 'yes' to restart application \nAnd press any key to quit");
string ans = Console.ReadLine();
if (ans != "yes")
{
Console.WriteLine("Thank you!");
break;
}
}
else
{
Console.WriteLine("Invalid operator!");
}
} while (operation != "*" || operation != "/" || operation != "+" || operation != "-");
}
}
static void Multiply()
{
double num1;
double num2;
double answer;
Console.WriteLine("\nEnter first number: ");
string text1 = Console.ReadLine();
if (double.TryParse(text1, out num1))
{
Console.WriteLine("Enter second number: ");
string text2 = Console.ReadLine();
if (double.TryParse(text2, out num2))
{
answer = num1 * num2;
Console.WriteLine("{0} * {1} = {2}", num1, num2, answer);
}
else { Console.WriteLine("Catch error"); }
}
else { Console.WriteLine("Catch error"); }
}
static void Divide()
{
double num1;
double num2;
double answer;
Console.WriteLine("\nEnter first number: ");
string text1 = Console.ReadLine();
if (double.TryParse(text1, out num1))
{
Console.WriteLine("Enter second number: ");
string text2 = Console.ReadLine();
if (double.TryParse(text2, out num2))
{
answer = num1 / num2;
if (num2 == 0)
{
Console.WriteLine("\nYou can't divide {0} to zero", num1);
}
else { Console.WriteLine("{0} / {1} = {2}", num1, num2, answer); }
}
else { Console.WriteLine("Catch error"); }
}
else { Console.WriteLine("Catch error"); }
}
static void Add()
{
double num1;
double num2;
double answer;
Console.WriteLine("\nEnter first number: ");
string text1 = Console.ReadLine();
if (double.TryParse(text1, out num1))
{
Console.WriteLine("Enter second number: ");
string text2 = Console.ReadLine();
if (double.TryParse(text2, out num2))
{
answer = num1 + num2;
Console.WriteLine("{0} + {1} = {2}", num1, num2, answer);
}
else { Console.WriteLine("Catch error"); }
}
else { Console.WriteLine("Catch error"); }
}
static void Subtract()
{
double num1;
double num2;
double answer;
Console.WriteLine("\nEnter first number: ");
string text1 = Console.ReadLine();
if (double.TryParse(text1, out num1))
{
Console.WriteLine("Enter second number: ");
string text2 = Console.ReadLine();
if (double.TryParse(text2, out num2))
{
answer = num1 - num2;
Console.WriteLine("{0} - {1} = {2}", num1, num2, answer);
}
else { Console.WriteLine("Catch error"); }
}
else { Console.WriteLine("Catch error"); }
}
}
}
- - - Updated - - -
So eto na yung sinasabi ko, busy sa work, halos wala ng oras magaral mag code, 1hr per day lang ako nakakabasa ng tutorial at sabay code na rin, mahirap kasi gigising ako ng maaga kahit madaling araw na uwi ko, pero tuloy tuloy lang walang araw na hindi ako nagbasa ng ebook at nginstall din ako ng excercise app sa phone ko more on console problems lang tulad ng basic input output, data types at if statement, tas konting looping, so far nasa topic ako na gagawa ng calculator sa console, na code ko mismo, walang ni anung video tutorial, code ako ng base sa nalaman ko at search sa google ng mga naencounter ko na problem,. eto yung code ko sa simple calculator,
sa mga marunong mag code jan sa c#, advise naman, working yung code ko pero alam ko ng maraming mali pagdating sa flow, pero nagwork sya sa gusto kong mangyari. check nyo na lang din po, napakasaya ko ng magawa ko to kasi from scratch ko to ginawa,.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Calculator
{
class Program
{
static void Main(string[] args)
{
string operation = "";
string again = "yes";
if (again == "yes")
{
do
{
Console.Write("What type of calculation do you want? ( *, /, + or - )");
operation = Console.ReadLine();
if (operation == "*")
{
Multiply();
Console.WriteLine("\nWrite 'yes' to restart application \nAnd press any key to quit");
string ans = Console.ReadLine();
if (ans != "yes")
{
Console.WriteLine("Thank you!");
break;
}
}
else if (operation == "/")
{
Divide();
Console.WriteLine("\nWrite 'yes' to restart application \nAnd press any key to quit");
string ans = Console.ReadLine();
if (ans != "yes")
{
Console.WriteLine("Thank you!");
break;
}
}
else if (operation == "+")
{
Add();
Console.WriteLine("\nWrite 'yes' to restart application \nAnd press any key to quit");
string ans = Console.ReadLine();
if (ans != "yes")
{
Console.WriteLine("Thank you!");
break;
}
}
else if (operation == "-")
{
Subtract();
Console.WriteLine("\nWrite 'yes' to restart application \nAnd press any key to quit");
string ans = Console.ReadLine();
if (ans != "yes")
{
Console.WriteLine("Thank you!");
break;
}
}
else
{
Console.WriteLine("Invalid operator!");
}
} while (operation != "*" || operation != "/" || operation != "+" || operation != "-");
}
}
static void Multiply()
{
double num1;
double num2;
double answer;
Console.WriteLine("\nEnter first number: ");
string text1 = Console.ReadLine();
if (double.TryParse(text1, out num1))
{
Console.WriteLine("Enter second number: ");
string text2 = Console.ReadLine();
if (double.TryParse(text2, out num2))
{
answer = num1 * num2;
Console.WriteLine("{0} * {1} = {2}", num1, num2, answer);
}
else { Console.WriteLine("Catch error"); }
}
else { Console.WriteLine("Catch error"); }
}
static void Divide()
{
double num1;
double num2;
double answer;
Console.WriteLine("\nEnter first number: ");
string text1 = Console.ReadLine();
if (double.TryParse(text1, out num1))
{
Console.WriteLine("Enter second number: ");
string text2 = Console.ReadLine();
if (double.TryParse(text2, out num2))
{
answer = num1 / num2;
if (num2 == 0)
{
Console.WriteLine("\nYou can't divide {0} to zero", num1);
}
else { Console.WriteLine("{0} / {1} = {2}", num1, num2, answer); }
}
else { Console.WriteLine("Catch error"); }
}
else { Console.WriteLine("Catch error"); }
}
static void Add()
{
double num1;
double num2;
double answer;
Console.WriteLine("\nEnter first number: ");
string text1 = Console.ReadLine();
if (double.TryParse(text1, out num1))
{
Console.WriteLine("Enter second number: ");
string text2 = Console.ReadLine();
if (double.TryParse(text2, out num2))
{
answer = num1 + num2;
Console.WriteLine("{0} + {1} = {2}", num1, num2, answer);
}
else { Console.WriteLine("Catch error"); }
}
else { Console.WriteLine("Catch error"); }
}
static void Subtract()
{
double num1;
double num2;
double answer;
Console.WriteLine("\nEnter first number: ");
string text1 = Console.ReadLine();
if (double.TryParse(text1, out num1))
{
Console.WriteLine("Enter second number: ");
string text2 = Console.ReadLine();
if (double.TryParse(text2, out num2))
{
answer = num1 - num2;
Console.WriteLine("{0} - {1} = {2}", num1, num2, answer);
}
else { Console.WriteLine("Catch error"); }
}
else { Console.WriteLine("Catch error"); }
}
}
}
- - - Updated - - -
wag nyo na [ansinin yung Catch error haha sinubukan ko kasi yung if statement kung papasok ba sya dun sa else kaya nilagyan ko ng Catch error na output, d ko na nabura,
plano ko kasi na gamitan ng try catch yan kaso di ko kabisado try catch kaya ng focus na lng ako sa if statement at do while loop, medyo magulo.