|
-
February 14th, 2011, 05:32 PM
#1
my simple console program is not working
Hi,
I am trying to use my C skills to make a simple console calculator, I have defined all the methods but I dont know where to call them, as it was not possible to call them in the main()...What I am doing wrong?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace simpleCalc
{
class Program
{
private void welcomeMessage()
{
Console.WriteLine("Welcome to a simple calculator by www.ElectronicsPub.com");
Console.WriteLine("Press 'q' at anytime to quite");
}
void inputLhs()
{
double lhs;
Console.WriteLine("Input first operand: ");
lhs = Int32.Parse(Console.ReadLine());
}
void inputRhs()
{
double Rhs;
Console.WriteLine("Input Second operand: ");
Rhs = Int32.Parse(Console.ReadLine());
}
void inputOperator()
{
char opr;
Console.WriteLine("Input operator (+ , -, *, / and %): ");
opr = (char) Console.Read();
while ((opr != '+') || (opr != '-') || (opr != '*') || (opr != '/') || (opr != '%') || opr ==null)
{
Console.WriteLine("Wrong operator has been entered, please input an operator again.");
Console.WriteLine("Input operator (+ , -, *, / and %): ");
opr = (char)Console.Read();
}
}
double calculate (char opr, double lhs, double rhs)
{
switch (opr)
{
case '+':
return lhs + rhs;
break;
case '-':
return lhs - rhs;
break;
case '*':
return lhs * rhs;
break;
case '/':
return lhs / rhs;
break;
case '%':
return lhs % rhs;
break;
default:
return 0;
break;
}
}
void showResult(double result)
{
Console.WriteLine(result);
}
static void Main(string[] args)
{
char reset = 'n';
while (reset != 'q')
{
// Have to use above functions here?!
}
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|