Exercise 2

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

Exercise 2: 1 (a) #include<iostream.

h> void main() { int x; cout << " Please Enter are number that greater than 100: "; cin >> x; cout<< endl; if ( x > 100 ) cout << " The number " << x << " is greater than 100 "<< endl; else cout << " Sorry, you enter the wrong number " << endl; }

1 (c) #include<iostream.h> void main() { int a,b,c, largest; cout << "Please enter three number :"<< endl; cin >> a; cin >> b; cin >> c; cout << endl; if (a>b) largest = a; else if (b>a) largest = b; if (largest < c) largest = c; cout << endl<< " The Largest Number is " << largest << endl; }

1 (b) #include<iostream> using namespace std; int main() { int y; cout << "Enter a negative number:"; cin >> y; cout << endl; if (y<0) cout << "The number" << " " << y << " negative number " << endl; else if ( y>0 ) cout << "The number" << " " << y << " is not negative number " << endl; return 0; }

2. #include <iostream.h> void main() { int number,quantity; float totalprice,price; cout<<"Please enter one digit (1-4)"<<endl; cin>>number; cout<<"How many quantity : "; cin>>quantity; switch(number) { case 1: price=1.10; break; case 2: price=4.56; break; case 3: price=7.89; break; case 4: price=0.95; break; default: cout<<"You enter invalid number"<<endl; } totalprice=price*quantity; cout<<"Your Total Price : "<<totalprice; }

You might also like