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
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
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
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program 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
Archived Comments
1. Very good example .. i ve written this program . P
View Tutorial By: gomz at 2011-09-26 12:33:54
2. superb its working perfect but one thing, we have
View Tutorial By: venkatachalam at 2013-03-14 16:35:00
3. Nice example. I think this is more idiomatic tho'.
View Tutorial By: John Morrison at 2010-03-28 14:55:07
4. I used two phrases of the security section for the
View Tutorial By: pabo at 2010-04-05 05:22:24
5. 0
View Tutorial By: zareen at 2011-08-20 08:27:28
6. I have download that 5 files .But how to run this
View Tutorial By: Unnati at 2011-07-07 06:07:26
7. You said the garbage collector can not be forced,
View Tutorial By: Biniam E at 2011-12-17 15:09:09
8. Nice example for FileReader and FileWriter,
View Tutorial By: Tim at 2009-10-21 17:31:00
9. Actually, looking at the code, it looks as somethi
View Tutorial By: Johnson at 2009-07-28 08:14:38
10. Hi you will run this program just as you run any o
View Tutorial By: Steven at 2008-10-14 09:03:28