Comment on Tutorial - Using switch Statements in C++ By Emiley J



Comment Added by : chika

Comment Added at : 2011-02-02 17:18:59

Comment on Tutorial : Using switch Statements in C++ By Emiley J
I want to ask, can a formula be inserted in this switch statement like the one I provided below?? Really need your help and comment.. Thank you..

#include <iostream>
using namespace std;
int main()
{
int price_before_discount, RM, dozen, total_price;

cout<< "How much is the price before discount for 1 dozen boxes of tissue?\n";
cout<<"RM ";
cin>>price_before_discount;
cout<<"\n\n";


cout<< "How many dozen boxes of tissue you buy?\n";
cin>>dozen;
cout<<"\n\n";


switch (dozen)
{
total_price = ((price_before_discount*dozen) * (95/100));
case '1': cout<< "Total price is RM ";
cout<<RM;
cout<<"\n\n";
break;

total_price = ((price_before_discount*dozen) * (88/100));
case '2': cout<< "Total price is RM ";
cout<<RM;
cout<<"\n\n";
break;

total_price = ((price_before_discount*dozen) * (75/100));
case '3': cout<< "Total price is RM ";
cout<<RM;
cout<<"\n\n";
break;

total_price = ((price_before_discount*dozen) * (60/100));
case '4' : cout<< "Total price is RM ";
cout<<RM;
cout<<"\n\n";
break;

total_price = ((price_before_discount*dozen) * (40/100));
default : cout<< "Total price is RM ";
cout<<RM;
cout<<"\n\n";
}

return 0;
}


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. great work..keep it up.
View Tutorial          By: faizaan at 2011-04-29 12:23:39

2. Hello friends can anybody tell me how to assign in
View Tutorial          By: gnvkdramesh at 2010-09-10 04:27:46

3. Thanks for this explanation. I'm not sure whether
View Tutorial          By: Venkatesh Challa at 2013-03-29 04:35:21

4. can you help me in codings for get an output like
View Tutorial          By: Sudhar at 2011-08-24 05:47:53

5. @Brian You surely can deploy your server code clas
View Tutorial          By: Ayush at 2013-06-10 13:22:38

6. How to execute above sqlstr file.
View Tutorial          By: shriyash at 2014-02-23 09:32:36

7. I don't think GSM/Modem simulatur, will get it wor
View Tutorial          By: Michael Chon at 2008-10-08 10:35:55

8. Thanks a lot lot lot for this... u saved me...
View Tutorial          By: Sourabh Idoorkar at 2011-06-10 04:25:10

9. Thnx Ramlak,but be ware about syntax errors.
View Tutorial          By: Saber at 2008-11-03 07:45:23

10. The best explanation....Thanq :)
View Tutorial          By: Gautham at 2012-01-29 05:05:48