why wont my if else statement work?
using System;
public
class TubSales{
public static void Main(){
string sales; double commRate = .10; double total; char response;Console.WriteLine("Enter the initial for the first name of the sales person (A, B or E)");
response = GetChar();
Console.Out.WriteLine("Enter the ammout of sales for this sales person");
sales = Console.ReadLine();
double commision = Convert.ToDouble(sales) / 10.0; if (response == 'A')commision = commision * commRate;
Console.WriteLine("The sales for Andrea is {0}", commision);
else if (response == 'B')commision = commision + commRate;
Console.WriteLine("The sales for Brittany is {0}", commision);
else if (response == 'E')commision = commision + commRate;
Console.WriteLine("The sales for Eric is {0}", commision);
}
public static char GetChar(){
string inputString; char answer;inputString = Console.ReadLine();
answer = Convert.ToChar(inputString);
return answer;}
}
SimonPosted Apr 6, 2007, 5:39 PM
You need to insert curly brackets surrounding what you want to execute inside the if and else conditions. Here's a corrected example :
if (response == 'A')
{
commision = commision * commRate;
Console.WriteLine("The sales for Andrea is {0}", commision);
}
else if (response == 'B')
{
commision = commision + commRate;
Console.WriteLine("The sales for Brittany is {0}", commision);
}
and so on...
Also, you might want to consider reading a C# book.
Simon