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



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. This is really a tremendous tutorials for the begi
View Tutorial          By: Raghvendra Dwivedi at 2010-09-01 10:22:42

2. hi,

i am trying to run this SMS jav

View Tutorial          By: Raghavendra at 2010-12-29 08:27:02

3. Good one......
Thanks.

View Tutorial          By: Suresh at 2013-03-14 07:38:45

4. May I have some examples of function exp and pow,
View Tutorial          By: janee at 2009-08-06 07:57:07

5. I love http://www.java-samples.com very much , I w
View Tutorial          By: Phongveth at 2009-03-13 13:15:04

6. the above is perfect, but when i hit the export bu
View Tutorial          By: CH at 2009-06-02 03:01:34

7. Great Work for JAVA Beginners
View Tutorial          By: Sudhir Rajgure at 2009-03-01 02:40:00

8. BEST COMMENT EVER:
"Reading the above

View Tutorial          By: Mr.X at 2013-10-02 16:31:42

9. hey..
shouldn't the 2nd java code have an o

View Tutorial          By: izzie at 2010-04-06 11:34:34

10. This is very useful for java beginners
View Tutorial          By: Syed Musthafa at 2011-11-20 07:11:50