use of SWITCH

C, C++, etc Programing examples. Post as many you can. Test the programs and discuss about the output of the programes.
Forum rules
Please Discuss & post only about the programes and its Output

use of SWITCH

Postby kantisuthar » Sun Apr 17, 2011 2:13 pm

#include<stdio.h>
#include<conio.h>
void main()
{
int choice,num;
float tot_price,price;
clrscr();
printf("\n\t*****************************************");
printf("\n\t Following shampoos are available");
printf("\n\t*****************************************");
printf("\n\t* Shampoos Price *");
printf("\n\t* 1 Clinic Plus 40.50 *");
printf("\n\t* 2 Pantene 42.00 *");
printf("\n\t* 3 Sunsilk 48.80 *");
printf("\n\t* 4 Nyle 65.00 *");
printf("\n\t* 5 Mugdha 95.00 *");
printf("\n\t*****************************************");
printf("\n\t Enter your choice : ");
scanf("%d",&choice);
printf("\n\t Enter quantity : ");
scanf("%d",&num);
switch(choice)
{
case 1:
price =40.50;
tot_price=num*price;
printf("\n\t You have to pay %0.2f Rs",tot_price);
break;
case 2:
price =42.00;
tot_price=num*price;
printf("\n\t You have to pay %0.2f Rs",tot_price);
break;
case 3:
price =48.80;
tot_price=num*price;
printf("\n\t You have to pay %0.2f Rs",tot_price);
break;
case 4:
price =65.00;
tot_price=num*price;
printf("\n\t You have to pay %0.2f Rs",tot_price);
break;
case 5:
price =95.00;
tot_price=num*price;
printf("\n\t You have to pay %0.2f Rs",tot_price);
break;
default:
printf("\n\t Your choice is invalid");
}
getch();
}
kantisuthar
Registered User
 
Posts: 6
Joined: Thu Apr 14, 2011 7:22 pm
membership: Associate Member of The Institution of Engineers (India)- AMIE

ad
 

Return to Computer Notes : Some Sample Programs

Who is online

Users browsing this forum: No registered users and 0 guests