[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 Discussion Refresh page to view new replies
 c# question. confused on one part
[VIEWED 3388 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 90 days
Recommended Popular Threads Controvertial Threads
What stocks to buy -- Any recommendation
Vintage Pictures of Kathmandu
Why does India turn a blind eye to rampant human trafficking and crime in red light districts
प्रियंका कार्की फोटो अबलम भाग २ , ३ जून २०१६ copyright @पुन्टर
नाज ब्रो को भाउजु को फोटो अल्बुम भाग १ , जून ३ २०१६
ChatSansar.com Naya Nepal Chat
Gauri Malla Sex Scandal
उस्तै उस्तै हामी
Dr. Fauci न टोक्नु न बोक्नु भएको छ ट्रुम्पलाई
Love Letters From The Past--SITARA
Nas and The Bokas: Coming to a Night Club near you
Conservative discussions
Fox News: Wear the Damn Mask, it is not political issue but a public health issue.
डर लाग्न थालेको छ |
Visit Reeyas Kitchen for Nepali Food Recipes
राजखानिको कथा ।
स्कूलमा पढेका कथा - भुतको शिकार, शिशिर बसन्तको कथा देखि टाउकोको मोल सम्म
पुलिसनी संग - आज शनिवार - अन्तिम भाग
K ho yo Paji Jaat
Four Characters and My Funeral
Nas and The Bokas: Coming to a Night Club near you
विद्या तेरो सिन्दूर खोइ, केपी ओली तेरो पोइ ..
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