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. hi sir
how can i get started if i want to

View Tutorial          By: simiyu at 2014-03-15 09:13:04

2. very Good machi.......
View Tutorial          By: Janani at 2013-03-04 06:37:47

3. There are 11 types of people.
Those who kno

View Tutorial          By: alphachap at 2011-03-07 10:53:44

4. @mahesh yes you can use this to connect to any db
View Tutorial          By: Rita sen at 2012-01-05 05:18:13

5. Thank you for this useful script!
View Tutorial          By: opencart module at 2011-01-03 21:21:37

6. sUPER eXPLAnation
View Tutorial          By: Surendra at 2015-06-13 07:23:56

7. Good Example esp. way it was presented.
View Tutorial          By: Arunlal at 2013-06-20 11:56:43

8. thanks a lot that helped.. =D
View Tutorial          By: Karthik at 2008-11-16 02:27:53

9. The program will work only need to change

View Tutorial          By: LEENA NARULA at 2012-06-15 06:45:06

10. crystal clear explanation
View Tutorial          By: digant at 2009-12-08 09:10:06