Question

Hello, I am having problems with my code. I thought i finished it but when I...

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();
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
Hello, I am having problems with my code. I thought i finished it but when I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT