[Show all top banners]

redlotus
Replies to this thread:

More by redlotus
What people are reading
Subscribers
Subscribers
[Total Subscribers 1]

Rolemodel
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 c# question. confused on one part
[VIEWED 5669 TIMES]
SAVE! for ease of future access.
Posted on 03-21-09 11:07 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

only problem with this program is that when I enter 'z' to exit it works but when I try'Z' it does not work. pls help




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

namespace assignment2_nepal
{
    class sales
    {
        public char empname;
        Double indsale;
        Double indsaleA = 0;
        Double indsaleB = 0;
        Double indsaleE = 0;
        Double indcomsaleA = 0;
        Double indcomsaleB = 0;
        Double indcomsaleE = 0;
        const Double commrate = 0.10;


        public void TotalSales()
        {

            Console.WriteLine("Enter A for Andrea or B or Brittany or E for Eric or z to quit:");
            Console.WriteLine("Enter a salesperson initial:");


            empname = Convert.ToChar(Console.ReadLine());

            while (empname !== 'z' || empname=='Z')
            {
              

                    if (empname == 'A' || empname == 'a')
                    {
                        Console.Out.WriteLine("Enter amount of sale");
                        indsale = Convert.ToDouble(Console.ReadLine());
                        indsaleA = indsaleA + indsale;
                    }
                    else if (empname == 'B' || empname == 'b')
                    {
                        Console.Out.WriteLine("Enter amount of sale");
                        indsale = Convert.ToDouble(Console.ReadLine());
                        indsaleB = indsaleB + indsale;
                    }
                    else if (empname == 'E' || empname == 'e')
                    {
                        Console.Out.WriteLine("Enter amount of sale");
                        indsale = Convert.ToDouble(Console.ReadLine());
                        indsaleE = indsaleE + indsale;
                    }
                    else
                        Console.Out.WriteLine("Invalid Entry! Please enter A, B or E for sales Employee and z to Quit");
                    Console.WriteLine("Enter another salesperson or z to quit");
                    empname = Convert.ToChar(Console.ReadLine());
                }
            }
      
        public void computesales()
        {
            indcomsaleA = commrate * indsaleA;
            indcomsaleB = commrate * indsaleB;
            indcomsaleE = commrate * indsaleE;
        }


        public void PrintSales()
        {
            Console.WriteLine("Andrea earned:               ${0}", indcomsaleA);
            Console.WriteLine("Brittany earned:             ${0}", indcomsaleB);
            Console.WriteLine("Eric earned:                 ${0}", indcomsaleE);
        }

    }
    class assignment2_nepal
    {
        static void Main(String[] args)
        {
            sales sale = new sales();
            sale.TotalSales();
            sale.computesales();
            sale.PrintSales();
        }

    }
}


 
Posted on 03-21-09 11:16 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

you are missing a NOT EQUAL TO in

while (empname !== 'z' || empname=='Z')

it should rather be :

while (empname != 'z' || empname!='Z')

you dont need !== ( makes no sense to me) ,  use !=

it runs your while loop till  empname has anything else than a 'z' or a 'Z'.

Last edited: 21-Mar-09 11:18 PM

 
Posted on 03-22-09 9:04 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

i tried you method but still it does not work.
 
Posted on 03-22-09 12:08 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I would suggest u to use do-while loop for efficiency.


and the condition of the loop termination should be as follows:


while ((empname != 'z') && (empname != 'Z'))


 


if u need, there is a complete code:


using System;


using System.Collections.Generic;


using System.Linq;


using System.Text;


namespace sajha


{


class sales


{


public char empname;


Double indsale;


Double indsaleA = 0;


Double indsaleB = 0;


Double indsaleE = 0;


Double indcomsaleA = 0;


Double indcomsaleB = 0;


Double indcomsaleE = 0;


const Double commrate = 0.10;


 


public void TotalSales()


{


do


{


Console.WriteLine("Enter A for Andrea or B or Brittany or E for Eric or z to quit:");


Console.WriteLine("Enter a salesperson initial:");


empname = Convert.ToChar(Console.ReadLine());


if (empname == 'A' || empname == 'a')


{


Console.Out.WriteLine("Enter amount of sale for Andrea");


indsale = Convert.ToDouble(Console.ReadLine());


indsaleA = indsaleA + indsale;


}


else if (empname == 'B' || empname == 'b')


{


Console.Out.WriteLine("Enter amount of sale for Brittany");


indsale = Convert.ToDouble(Console.ReadLine());


indsaleB = indsaleB + indsale;


}


else if (empname == 'E' || empname == 'e')


{


Console.Out.WriteLine("Enter amount of sale for Eric");


indsale = Convert.ToDouble(Console.ReadLine());


indsaleE = indsaleE + indsale;


}


}while ((empname != 'z') && (empname != 'Z'));


}


 


public void computesales()


{


indcomsaleA = commrate * indsaleA;


indcomsaleB = commrate * indsaleB;


indcomsaleE = commrate * indsaleE;


}


 


public void PrintSales()


{


Console.WriteLine("Andrea earned: ${0}", indcomsaleA);


Console.WriteLine("Brittany earned: ${0}", indcomsaleB);


Console.WriteLine("Eric earned: ${0}", indcomsaleE);


}


class Program


{


static void Main(string[] args)


{


sales sale = new sales();


sale.TotalSales();


sale.computesales();


sale.PrintSales();


Console.WriteLine("Press any key to EXIT !");


Console.ReadLine();


}


}


}


}


 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 30 days
Recommended Popular Threads Controvertial Threads
TPS Re-registration case still pending ..
I hope all the fake Nepali refugee get deported
and it begins - on Day 1 Trump will begin operations to deport millions of undocumented immigrants
Travel Document for TPS (approved)
To Sajha admin
Those who are in TPS, what’s your backup plan?
MAGA and all how do you feel about Trumps cabinet pick?
All the Qatar ailines from Nepal canceled to USA
MAGA मार्का कुरा पढेर दिमाग नखपाउनुस !
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters