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
- React Native
- 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
Related Tutorials
Read a file having a list of telnet commands and execute them one by one using Java
Open a .docx file and show content in a TextArea using Java
Step by Step guide to setup freetts for Java
Of Object, equals (), == and hashCode ()
Using the AWS SDK for Java in Eclipse
DateFormat sample program in Java
concurrent.Flow instead of Observable class in Java
Calculator application in Java
Sending Email from Java application (using gmail)