QUESTION 1
a) Initializing variable Pi with the value 3.14
const Pi=3.14;
b) Declare a variable named perimeter with double data type
double perimeter;
c) Give instruction that allowed user to input data
cout<<"Enter data=";
cin>>data;
d) Input number of computer using variable
cout<<"Enter number=";
cin>>nimber;
QUESTION 2
Change the if...else statement below to switch...case statement
#include<iostream.h>
main()
{
int selection,quantity;
float price;
cout<<"1.pen=rm0.50";
cout<<"2.pencil=rm0.30;
cout<<"3.ruler=rm0.20";
cout<<"4.Erasor=rm0.10";
cin>>selection;
cin>>quantity;
if(selection==1)
{price=quantity*0.50;}
else if(selection==2)
{price=quantity*0.30;}
else if(selection==3)
{price=quantity*0.20;}
else if(selection==4)
{price=quantity*0.10;}
else
{cout<<"Invalid selection";}
cout<<"the price is :"<<price;
return 0;
}
#include<iostream.h>
main()
{
int selection,quantity;
float price;
cout<<"1.pen=rm0.50";
cout<<"2.pencil=rm0.30;
cout<<"3.ruler=rm0.20";
cout<<"4.Erasor=rm0.10";
cin>>selection;
cin>>quantity;
switch(quantity,selection)
{
case 1:"price=quantity*0.50";break;
case 2:"price=quantity*0.30";break;
case 3:"price=quantity*0.20";break;
case 4:"price=quantity*0.10";break;
default:cout<<"Invalid selection";
cout<<"The price is :"<<price;
return 0;
}
No comments:
Post a Comment