M
Mikestriken
Guest
So I am working on my current exercise in my class and the objective is as follows:
"Three salespeople work at Sunshine Hot Tubs—Andrea, Brittany, and Eric. Write a console-based application that prompts the user for a salesperson’s initial (‘A’, ‘B’, or ‘E’). While the user does not type ‘Z’, continue by prompting for the amount of a sale the salesperson made. Calculate the salesperson’s commission as 10% of the sale amount, and add the commission to a running total for that salesperson. After the user types ‘Z’ for an initial, display each salesperson’s total commission earned. Save the file as TubSales.cs."
Now I know that I can cheat and literally copy and paste that online and get the answer, but I want to become a programmer in the future for a career so I am actually trying to make this work by myself.
Anyways here is what I have so far:
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
// Dim and start
double saleA = 0, saleB = 0, saleE = 0, commissionA = 0, totalA = 0, commissionB = 0, totalB = 0, commissionE = 0, totalE = 0;
int done = 0, logoff = 0;
Console.WriteLine("Give me your initial.....");
// Initial Check
string initial = Console.ReadLine();
while (initial != "A" && initial != "B" && initial != "E")
{
Console.WriteLine("YOU'RE NOT DAVE!!!");
initial = Console.ReadLine();
}
// Hello Initial
if (initial == "A")
Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "B")
Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "E")
Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
// Calculate initial "A"'s values
while (logoff == 0)
{
do
{
do
{
saleA += Convert.ToDouble(Console.ReadLine());
commissionA = saleA * .10;
totalA = commissionA + saleA;
Console.WriteLine("Enter \"Z\" if you are finished, continue?");
} while (Console.ReadLine() != "Z" && initial == "A");
Console.WriteLine("Current Sales are: {0}", saleA);
done = 1;
} while (initial == "A" && done == 0);
logoff = 1;
}
// RESET VALUES
done = 0;
Console.WriteLine("Give me your initial.....");
// Initial Check
initial = Console.ReadLine();
while (initial != "A" && initial != "B" && initial != "E")
{
Console.WriteLine("YOU'RE NOT DAVE!!!");
initial = Console.ReadLine();
}
// Initial hello
if (initial == "A")
Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "B")
Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "E")
Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
// Calculate initial "B"'s values
while (Console.ReadLine() != "Z" && initial == "B")
{
saleB += Convert.ToDouble(Console.ReadLine());
commissionB = saleB * .10;
totalB = commissionB + saleB;
Console.ReadLine();
}
// Initial Check
initial = Console.ReadLine();
while (initial != "A" && initial != "B" && initial != "E")
{
Console.WriteLine("YOU'RE NOT DAVE!!!");
initial = Console.ReadLine();
}
// Inital hello
if (initial == "A")
Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "B")
Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "E")
Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
// Calculate initial "E"'s values
while (Console.ReadLine() != "Z" && initial == "E")
{
saleE += Convert.ToDouble(Console.ReadLine());
commissionE = saleE * .10;
totalE = commissionE + saleE;
Console.ReadLine();
}
// Spacer
Console.WriteLine();
// Andrea stats
Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
"sale of: " + saleA.ToString("C2") + Environment.NewLine +
"commission of: " + commissionA.ToString("C2") + Environment.NewLine +
"total of: " + totalA.ToString("C2"));
// Brittany stats
Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
"sale of: " + saleB.ToString("C2") + Environment.NewLine +
"commission of: " + commissionB.ToString("C2") + Environment.NewLine +
"total of: " + totalB.ToString("C2"));
// Eric stats
Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
"sale of: " + saleE.ToString("C2") + Environment.NewLine +
"commission of: " + commissionE.ToString("C2") + Environment.NewLine +
"total of: " + totalE.ToString("C2"));
}
}
}
But what I am focusing on for now is under "Calculate Initial "A"'s Values" in this code block:
// Calculate initial "A"'s values
while (logoff == 0)
{
do
{
do
{
saleA += Convert.ToDouble(Console.ReadLine());
commissionA = saleA * .10;
totalA = commissionA + saleA;
Console.WriteLine("Enter \"Z\" if you are finished, continue?");
} while (Console.ReadLine() != "Z" && initial == "A");
Console.WriteLine("Current Sales are: {0}", saleA);
done = 1;
} while (initial == "A" && done == 0);
logoff = 1;
}
So as you can see by my vain attempt with the variable "logoff", I want it so that as soon as all the calculations have been completed for "Andrea", it loops back and then it continues down.
I am doing this so that if the person specifies that he is editing Andrea the first time, he can type "A" again to edit Andrea's values instead of having to either select editing Brittany or Eric....
So is there a way to loop back like that more effectively? (and yes I am being extra for this assignment as I usually do because I want to become a programmer)
Continue reading...
"Three salespeople work at Sunshine Hot Tubs—Andrea, Brittany, and Eric. Write a console-based application that prompts the user for a salesperson’s initial (‘A’, ‘B’, or ‘E’). While the user does not type ‘Z’, continue by prompting for the amount of a sale the salesperson made. Calculate the salesperson’s commission as 10% of the sale amount, and add the commission to a running total for that salesperson. After the user types ‘Z’ for an initial, display each salesperson’s total commission earned. Save the file as TubSales.cs."
Now I know that I can cheat and literally copy and paste that online and get the answer, but I want to become a programmer in the future for a career so I am actually trying to make this work by myself.
Anyways here is what I have so far:
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
// Dim and start
double saleA = 0, saleB = 0, saleE = 0, commissionA = 0, totalA = 0, commissionB = 0, totalB = 0, commissionE = 0, totalE = 0;
int done = 0, logoff = 0;
Console.WriteLine("Give me your initial.....");
// Initial Check
string initial = Console.ReadLine();
while (initial != "A" && initial != "B" && initial != "E")
{
Console.WriteLine("YOU'RE NOT DAVE!!!");
initial = Console.ReadLine();
}
// Hello Initial
if (initial == "A")
Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "B")
Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "E")
Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
// Calculate initial "A"'s values
while (logoff == 0)
{
do
{
do
{
saleA += Convert.ToDouble(Console.ReadLine());
commissionA = saleA * .10;
totalA = commissionA + saleA;
Console.WriteLine("Enter \"Z\" if you are finished, continue?");
} while (Console.ReadLine() != "Z" && initial == "A");
Console.WriteLine("Current Sales are: {0}", saleA);
done = 1;
} while (initial == "A" && done == 0);
logoff = 1;
}
// RESET VALUES
done = 0;
Console.WriteLine("Give me your initial.....");
// Initial Check
initial = Console.ReadLine();
while (initial != "A" && initial != "B" && initial != "E")
{
Console.WriteLine("YOU'RE NOT DAVE!!!");
initial = Console.ReadLine();
}
// Initial hello
if (initial == "A")
Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "B")
Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "E")
Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
// Calculate initial "B"'s values
while (Console.ReadLine() != "Z" && initial == "B")
{
saleB += Convert.ToDouble(Console.ReadLine());
commissionB = saleB * .10;
totalB = commissionB + saleB;
Console.ReadLine();
}
// Initial Check
initial = Console.ReadLine();
while (initial != "A" && initial != "B" && initial != "E")
{
Console.WriteLine("YOU'RE NOT DAVE!!!");
initial = Console.ReadLine();
}
// Inital hello
if (initial == "A")
Console.WriteLine("Hello Andrea!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "B")
Console.WriteLine("Hello Brittany!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
else if (initial == "E")
Console.WriteLine("Hello Eric!" + Environment.NewLine + "Insert the sales you have gained, and enter \"Z\" when you are finished....");
// Calculate initial "E"'s values
while (Console.ReadLine() != "Z" && initial == "E")
{
saleE += Convert.ToDouble(Console.ReadLine());
commissionE = saleE * .10;
totalE = commissionE + saleE;
Console.ReadLine();
}
// Spacer
Console.WriteLine();
// Andrea stats
Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
"sale of: " + saleA.ToString("C2") + Environment.NewLine +
"commission of: " + commissionA.ToString("C2") + Environment.NewLine +
"total of: " + totalA.ToString("C2"));
// Brittany stats
Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
"sale of: " + saleB.ToString("C2") + Environment.NewLine +
"commission of: " + commissionB.ToString("C2") + Environment.NewLine +
"total of: " + totalB.ToString("C2"));
// Eric stats
Console.WriteLine("Sales Person Andrea has made a:" + Environment.NewLine +
"sale of: " + saleE.ToString("C2") + Environment.NewLine +
"commission of: " + commissionE.ToString("C2") + Environment.NewLine +
"total of: " + totalE.ToString("C2"));
}
}
}
But what I am focusing on for now is under "Calculate Initial "A"'s Values" in this code block:
// Calculate initial "A"'s values
while (logoff == 0)
{
do
{
do
{
saleA += Convert.ToDouble(Console.ReadLine());
commissionA = saleA * .10;
totalA = commissionA + saleA;
Console.WriteLine("Enter \"Z\" if you are finished, continue?");
} while (Console.ReadLine() != "Z" && initial == "A");
Console.WriteLine("Current Sales are: {0}", saleA);
done = 1;
} while (initial == "A" && done == 0);
logoff = 1;
}
So as you can see by my vain attempt with the variable "logoff", I want it so that as soon as all the calculations have been completed for "Andrea", it loops back and then it continues down.
I am doing this so that if the person specifies that he is editing Andrea the first time, he can type "A" again to edit Andrea's values instead of having to either select editing Brittany or Eric....
So is there a way to loop back like that more effectively? (and yes I am being extra for this assignment as I usually do because I want to become a programmer)
Continue reading...