Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

When I run my program it will not let me input decimal numbers. Numbers with no

ID: 3654106 • Letter: W

Question

When I run my program it will not let me input decimal numbers. Numbers with no decimals are okay. How do I fix this in C# program. using System; public class GradeBook { public string CourseName { get; set; } public GradeBook(string name) { CourseName = name; } public void DisplayMessage() { Console.WriteLine("Welcome to Carl's sales calculator for {0}!/n", CourseName); Console.ReadLine(); } public void DetermineSalary() { int total; // sum of sales int salesCounter; // number ofsales entered int sales; // sales value int salary; // initialization phase total = 0; // initialize total salesCounter = 0; // initialize loop counter // processing phase // // prompt for and read a sale from the user Console.Write("Enter amount of sale or -1 to quit: "); sales = Convert.ToInt32(Console.ReadLine()); // loop until sentinel value is read from user while (sales != -1) { total = total + sales; // add sale to total salesCounter = salesCounter + 1; // increment counter // prompt for and read the next sale from the user Console.Write("Enter amount of sale or -1 to quit: "); sales = Convert.ToInt32(Console.ReadLine()); } // end while // termination phase // if the user entered at least one sale... if (salesCounter != 0) { // calculate the total of all sales sales = total; salary = 200 + (sales * 0.09m); // display the total of sales Console.WriteLine("Sales is {0:F}", total); Console.ReadLine(); } // end if else // no sales were entered, so output error message Console.WriteLine("No sales were entered"); Console.ReadLine(); } // end }

Explanation / Answer

you have declared all your variables as "int", that is why decimals are not allowed because "int" datatype deals only with integers i.e. without decimals. change the variables to "float" or "double" then it will compile without any error.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote