Hello, I am having problems with my code. I thought i finished it but when I run the code it does not run correctly. Could some please assist?
The instructions are in this Google Document: https://drive.google.com/file/d/1T_DoXMgSoGF-GMv9CDIWGFkfAVpIFdoR/view?usp=sharing
Here is my code in C #.
using System;
class Program
{
static void Main()
{
double[] person1 = new double[5];
double[] person2 = new double[5];
double[] person3 = new double[5];
int person;
int product;
double amount;
double person1tot=0;
double person2tot=0;
double person3tot=0;
double total;
do
{
Console.Write("Enter Salesperson number (1-3) or other number to
quit: ");
person = int.Parse(Console.ReadLine());
if (person > 0 && person < 5)
{
Console.Write("Enter product number (1-5): ");
product = int.Parse(Console.ReadLine());
Console.Write("Enter amount sold: ");
amount = double.Parse(Console.ReadLine());
if (person == 1)
{
person1[product - 1] = amount;
}
if (person == 2)
{
person2[product - 1] = amount;
}
else
{
person3[product - 1] = amount;
}
}
} while (person > 0 && person < 5);
Console.WriteLine("{0,-15}{1,-15:c}{2,-15:c}{3,-15:c}{4,-15:c}",
"Product", "Salesperson 1", "Salesperson 2", "Salesperson 3",
"All");
for (int i = 0; i < 5; i++)// adds total for each person
{
person1tot += person1[i];
person2tot += person2[i];
person3tot += person3[i];
total = person1tot + person2tot + person3tot;
Console.WriteLine("{0,-15}{1,-15:c}{2,-15:c}{3,-15:c}{4,-15:c}",
i+1, person1tot, person2tot,person3tot,total);
}
total = person1tot + person2tot + person3tot;
Console.WriteLine("{0,-15}{1,-15:c}{2,-15:c}{3,-15:c}{4,-15:c}",
"Total", person1tot, person2tot, person3tot, total);
Console.ReadKey();
}
}
Please refer the code below:
class Program
{
static void Main()
{
double[] person1 = new double[5];
double[] person2 = new double[5];
double[] person3 = new double[5];
int person;
int product;
double amount;
double person1tot = 0;
double person2tot = 0;
double person3tot = 0;
double total;
do
{
Console.Write("Enter Salesperson number (1-3) or other number to
quit: ");
person = int.Parse(Console.ReadLine());
if (person > 0 && person < 5)
{
Console.Write("Enter product number (1-5): ");
product = int.Parse(Console.ReadLine());
Console.Write("Enter amount sold: ");
amount = double.Parse(Console.ReadLine());
if (person == 1)
{
person1[product - 1] = amount;
}
if (person == 2)
{
person2[product - 1] = amount;
}
if(person==3)
{
person3[product - 1] = amount;
}
}
} while (person > 0 && person < 5);
Console.WriteLine("{0,-15}{1,-15:c}{2,-15:c}{3,-15:c}{4,-15:c}",
"Product", "Salesperson 1", "Salesperson 2", "Salesperson 3",
"All");
for (int i = 0; i < 5; i++)// adds total for each person
{
person1tot = person1[i];
person2tot = person2[i];
person3tot = person3[i];
total = person1tot + person2tot + person3tot;
Console.WriteLine("{0,-15}{1,-15:c}{2,-15:c}{3,-15:c}{4,-15:c}", i
+ 1, person1tot, person2tot, person3tot, total);
}
total = person1tot + person2tot + person3tot;
Console.WriteLine("{0,-15}{1,-15:c}{2,-15:c}{3,-15:c}{4,-15:c}",
"Total", person1tot, person2tot, person3tot, total);
Console.ReadKey();
}
}
Note: Few correction in if else and summing values
Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again.
Hello, I am having problems with my code. I thought i finished it but when I...