[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 4611 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
What are your first memories of when Nepal Television Began?
मन भित्र को पत्रै पत्र!
काेराेना सङ्क्रमणबाट बच्न Immunity बढाउन के के खाने ?How to increase immunity against COVID - 19?
TPS Work Permit/How long your took?
चितवनको होस्टलमा १३ वर्षीया शालिन पोखरेल झुण्डिएको अवस्था - बलात्कार पछि हत्याको शंका - होस्टेलहरु असुरक्षित
Nepali doctors future black or white usa ?
Another Song Playing In My Mind
nrn citizenship
TPS Renewal Reregistration
हेर अमेरिकामा नेपालीहरुको बेज्जत
WHAT DO YOU GUYS THINK ABOUT THIS?
Send Parcels from USA to Nepal & Worldwide.
Why is every youths leaving Nepal? Why are not youths entering politics and serving the country, starting business etc?
Is money sent to support family tax deductible?
Nearly one-third of Americans support autocracy, poll finds
Alert: Turbo Cancers: A Rising Global Threat
महँगो अण्डाको पिकल्प : कुखुरा र खोर भाडामा लिने
Informatica consultancy share
Travelling on TPS advance travel document to different country...
Are you ready to know the truth?
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