Question

Fix the code using C# shown below to show the repitition as seen on the example screenshot: (Invalid error must repeat):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Program
{
class Program
{
static void Main(string[] args)
{
double num, count = 0;
double Tax = 0.00, ship = 5.00, sum = 0.00;
double grandtotal;
char line;

//Set run =true
bool run=true;
do
{

//read amount of item
Console.WriteLine("What is the amount of item : ");
//read in num
run=double.TryParse(Console.ReadLine(), out num);
//check if run is not true that means returns false if entered
//value is not number of type double
while (!run)
{
//prompt for value
Console.WriteLine("Please re-enter : ");
Console.WriteLine("What is the amount of item : ");
//read in num
run = double.TryParse(Console.ReadLine(), out num);

//check if run is true and num is less than 0
if (run && num < 0)
{
Console.WriteLine("Please re-enter : ");
run = double.TryParse(Console.ReadLine(), out num);
}
}

sum = sum + num;
count = count + 1;
Console.WriteLine("\nDo you want to purchase more items ? -Y or N : ");
line = char.Parse(Console.ReadLine());

} while (line != 'n' && line != 'N');

Console.WriteLine("-----------------------------------------------");
Console.WriteLine("\t\tSales Receipt\t\t\t");
Console.WriteLine("Total Purchase : \t\t\t$" + string.Format("{0:0.00}", sum));
ship = sum / 10;
Console.WriteLine("Shippint charges :\t\t\t$" + string.Format("{0:0.00}", ship));
Console.WriteLine("Number of item purchased:\t\t" + count);

if (count <= 3)
{
ship = 3.50;
Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
}
else if (count > 3 && count < 7)
{
ship = 5.00;
Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
}
else if (count > 6 && count < 11)
{
ship = 7.00;
Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
}
else if (count > 10 && count < 16)
{
ship = 9.00;
Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
}
else
{
ship = 10.00;
Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
}

Console.WriteLine("-----------------------------------------------");
grandtotal = sum + ship + Tax;
Console.WriteLine("Grand Total : \t\t\t\t$" + string.Format("{0:0.00}", grandtotal));


Console.ReadKey();

}
}
}

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

Updated C# Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            double num, count = 0;
            double Tax = 0.00, ship = 5.00, sum = 0.00;
            double grandtotal;
            char line;

            //Set run =true
            bool run = true;
            do
            {
                //read amount of item
                Console.Write("What is the amount of item? - ");
                //read in num
                run = double.TryParse(Console.ReadLine(), out num);
                //check if run is not true that means returns false if entered
                //value is not number of type double
                while (!run || num < 0)
                {
                    //prompt for value
                    Console.Write("Invalid data entered - Please re-enter the amount of item - ");
                    //read in num
                    run = double.TryParse(Console.ReadLine(), out num);
                }

                sum = sum + num;
                count = count + 1;
                Console.WriteLine("\nDo you want to purchase more items ? -Y or N : ");
                line = char.Parse(Console.ReadLine());

            } while (line != 'n' && line != 'N');

            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine("\t\tSales Receipt\t\t\t");
            Console.WriteLine("Total Purchase : \t\t\t$" + string.Format("{0:0.00}", sum));
            ship = sum / 10;
            Console.WriteLine("Shippint charges :\t\t\t$" + string.Format("{0:0.00}", ship));
            Console.WriteLine("Number of item purchased:\t\t" + count);

            if (count <= 3)
            {
                ship = 3.50;
                Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
            }
            else if (count > 3 && count < 7)
            {
                ship = 5.00;
                Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
            }
            else if (count > 6 && count < 11)
            {
                ship = 7.00;
                Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
            }
            else if (count > 10 && count < 16)
            {
                ship = 9.00;
                Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
            }
            else
            {
                ship = 10.00;
                Console.WriteLine("Sales Tax:\t\t\t\t$" + string.Format("{0:0.00}", ship));
            }

            Console.WriteLine("-----------------------------------------------");
            grandtotal = sum + ship + Tax;
            Console.WriteLine("Grand Total : \t\t\t\t$" + string.Format("{0:0.00}", grandtotal));


            Console.ReadKey();

        }
    }
}

_________________________________________________________________________________________________

Sample Run:

file:///c/users/saibabu/documents/visual studio 2010/Projects/Program/Program/bin/Debug/Prog.... S What is the amount of item

Add a comment
Know the answer?
Add Answer to:
Fix the code using C# shown below to show the repitition as seen on the example...
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
  • I am writing a console application in C#. It is a receipt where the user inputs...

    I am writing a console application in C#. It is a receipt where the user inputs the item then quantity and then price per item. It is then validated through regular expressions. I need to put this in a multidimensional array to print out (command line print), like each row would have a columns for item, quantity, price and then subtotal for each item, but cannot figure it out. I also need the regular expression in a do while loop...

  • So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I...

    So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I need help editing my code. I want my quiz to clear the screen after each question. It should do one question at a time and then give a retry of each question that was wrong. The right answer should appear if the retry is wrong. After the 1 retry of each question, a grade should appear. Please note and explain the changes you make...

  • (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example,...

    (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example, if a user inputs a repeated number the program should regenerate or ask to enter again. If needed, here is the program requirements: Create a lottery game application. Generate four random numbers, each between 1 and 10. Allow the user to guess four numbers. Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess,...

  • Java Programming Language Edit and modify from the given code Perform the exact same logic, except...

    Java Programming Language Edit and modify from the given code Perform the exact same logic, except . . . The numeric ranges and corresponding letter grade will be stored in a file. Need error checking for: Being able to open the text file. The data makes sense: 1 text line of data would be 100 = A. Read in all of the numeric grades and letter grades and stored them into an array or arraylist. Then do the same logic....

  • PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP...

    PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here    do { // program here             }while (true);    } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...

  • Describe the necessary user inputs from the program using the following table format. Choose the appropriate...

    Describe the necessary user inputs from the program using the following table format. Choose the appropriate data type to store each user input and explain your choice. Input data type chosen and why Note that you are expected to take into consideration the value(s) of each transaction category. For example, your program should assess the transaction amount of each bill paid by the user before classifying it under the bill payment category. Below is the python program: from math import...

  • This is done in c programming and i have the code for the programs that it wants at the bottom i ...

    This is done in c programming and i have the code for the programs that it wants at the bottom i jut dont know how to call the functions Program 2:Tip,Tax,Total int main(void) {    // Constant and Variable Declarations    double costTotal= 0;    double taxTotal = 0;    double totalBill = 0;    double tipPercent = 0;    // *** Your program goes here ***    printf("Enter amount of the bill: $");    scanf("%lf", &costTotal);    printf("\n");    // *** processing ***    taxTotal = 0.07 * costTotal;    totalBill...

  • Rewrite the following program using the DecimalFormat class so that your output looks like that below....

    Rewrite the following program using the DecimalFormat class so that your output looks like that below. Once again, the example is not calculated as 3/10ths of a percent. Welcome to NIU Investments! Please enter the amount you would like to invest today: 34543.25 Total Investment: $34,543.25 Service Charge: $22.33    ------------- Total Amount Due: $34,565.58 Thank you for your investment! Program: package org.students; import java.util.Scanner; public class NIUInvestments {    //Declaring constant    public static final double SCHARGE=0.0006464;    public...

  • Assignment Develop a program to analyze one or more numbers entered by a user. The user...

    Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...

  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.                                                                                                           Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop                                                                                              int cnt = 1;     do {     cnt += 3;     } while (cnt < 25);     cout << cnt; It runs ________ times    ...

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
ADVERTISEMENT