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. This post is about adding an application icon to a
View Tutorial          By: Rick at 2011-11-04 16:48:16

2. You don't have to call the constructors. When you
View Tutorial          By: Watson at 2011-05-04 10:44:23

3. the best site i have found so far for clearing my
View Tutorial          By: darkknight at 2013-06-05 05:54:10

4. Excellent example
View Tutorial          By: Dinesh Patil at 2012-06-19 08:30:48

5. u can try this out it will satisify u:)
imp

View Tutorial          By: vallabh at 2014-10-04 17:44:18

6. Hi, i am trying this code but at compile time it w
View Tutorial          By: swapnil at 2012-12-16 01:37:57

7. Hello friends ,
I have downloaded all 5 fil

View Tutorial          By: pinnacle at 2013-06-08 13:08:55

8. Float f=99.7f;
int i1=Integer.parseInt(f);<

View Tutorial          By: Ashwin at 2012-12-23 05:14:04

9. Thks a lot..... The way of giving explanation and
View Tutorial          By: Hari at 2011-04-08 02:58:06

10. hi , sending of sms is failing. Please help me in
View Tutorial          By: sudhakar at 2009-06-19 09:39:55