skip to main | skip to sidebar

FUNDAMENTAL OF PROGRAMMING

Saturday, March 26, 2011

EXERCISE 2

QUESTION 1:
a) intializing variable pi with the value 3.14
ans: float pi = 3.14
b) Declare a variable named parameter with double data type
ans: Double perimeter;
c) Give instruction that allowed user to input data
ans: cout<< "enter your data";
cin>> data;
d) Input number of computer using variable
ans:cout<<"enter number";
cin>>number;


QUESTION 2:
Change the if....else statement below to switch....case statement
#include
main ()
{
int selection,quantity;
float price;
cout<<"1.pen = Rm0.50";
cout<<"2.pencil = Rm0.30";
cout<<"3.ruler = Rm0.20";
cout<<"4.eraser = 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 : "<

#include
main ()
{
int selection,quantity;
float price;
cout<<"1.pen = Rm0.50";
cout<<"2.pencil = Rm0.30";
cout<<"3.ruler = Rm0.20";
cout<<"4.eraser = Rm0.10";
cin>>selection;
cin>>quantity;
switch (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: "<
return 0;
}
coret curhat karra mc'yudied at 7:44 PM

0 comments:

Post a Comment

thanks for comment..

Newer Post » « Older Post Home
Subscribe to: Post Comments (Atom)

MusicPlaylist
Music Playlist at MixPod.com

Followers

counters counters
counters
 stalkers reading

chit chakkks

Blog Archive

  • ▼  2011 (16)
    • ►  February (9)
    • ▼  March (7)
      • IF ELSE TO SWITCH CASE
      • LOOP AND WHILE
      • EXERCISE exam
      • EXERCISE 2
      • ASSIGNMENT 1
      • CORDING ASSIGNMENT 1
      • ASSIGNMENT 2

About Me

My photo
karra mc'yudied
stupid naive falling in love.. very sensitive n secretive.. love to be alone..
View my complete profile
Karra Mc'yudied II

Create your badge
Karra Mc'yudied

Create your badge

i heart u most

i heart u most
 
Copyright © FUNDAMENTAL OF PROGRAMMING. All rights reserved.
Blogger templates created by Templates Block
Wordpress theme by Uno Design Studio