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. Thanks for this tutorial . This provides me lots
View Tutorial          By: Pranit at 2011-07-25 09:12:29

2. "If you enter zero, the assert() macro forces
View Tutorial          By: czx at 2010-09-17 07:23:20

3. My teacher doesnt teach me right!
View Tutorial          By: Anon at 2009-02-20 07:16:08

4. neded defination in clear
View Tutorial          By: venkat at 2011-07-04 06:31:19

5. very good....
View Tutorial          By: satish at 2010-03-03 22:47:25

6. I want to redirect from a servlet page to another
View Tutorial          By: dinesh at 2014-10-20 16:44:26

7. Hi All,
I can send sms successfully from Wi

View Tutorial          By: henrynawaung at 2008-11-14 06:41:13

8. send c++ programs on every topic of c++
View Tutorial          By: mandeep at 2009-07-11 00:50:23

9. pLZ LET US FIND SOME PROGRAMS INVOLVING CONVERSION
View Tutorial          By: Ishaq at 2009-02-12 00:27:59

10. i want to SCJP exam ,tell how to apply for this ex
View Tutorial          By: PRABAKARAN at 2013-07-16 13:32:50