samedi 28 octobre 2017

do while loop return 2 if statements

I have the following code which is returning 2 parameters at once. Namely if I type in -25 I get two results where I only want the one that states you get "0" at the rate of 0. Please see attached picture for output reference

Attached image.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace Problem2
{
    class Program
    {
        static void Main(string[] args)
        {
            const decimal fifty = 7.25M;
            const decimal hundred = 15.75M;
            const decimal overhundred = 21.50M;
            decimal sumfifty = 0.0M;
            decimal sumhundred = 0.00M;
            decimal sumoverhundred = 0.00M;
            decimal sentinel;

            WriteLine("\n*** PROBLEM 4 ***\n");


            do
            {
                Write("How many pieces? ");
                Write("Enter any whole number or -999 to quit: ");
                stenter code herering input = ReadLine();
                sentinel = Convert.ToDecimal(input);

                sumfifty = sentinel * fifty;
                sumhundred = sentinel * hundred;
                sumoverhundred = sentinel * overhundred;

                if (sentinel >= -998 && sentinel <= 0)
                    {
                        WriteLine("At 0 pieces at $0.00 per piece, you've earned $0.00.");
                    }
                    if (sentinel >= 1 && sentinel <= 49)
                    {
                        WriteLine("At {0} pieces at {1} per piece, you've earned {2}.\n", sentinel, fifty, sumfifty);
                    }
                    else if (sentinel >= 50 && sentinel <= 100)
                    {
                        WriteLine("At {0} pieces at {1} per piece, you've earned {2}.\n", sentinel, hundred, sumhundred);
                    }
                    else
                    {
                        WriteLine("At {0} pieces at {1} per piece, you've earned {2}.\n", sentinel, overhundred, sumoverhundred);
                    }
                //}

            } while (sentinel != -999);

            WriteLine("\nThanks for using our system.");
            Write("Press any key to continue...");
            ReadKey();
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire