Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

(PF) C++

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

#include<iostream>

using namespace std;


int main()
{
float a,b,c,d;
cout<<"Enter a number: ";
cin>>a;
cout<<"Enter a number: ";
cin>>b;
c=(a<b) ? a:b;
d=(a>b) ? a:b;
cout<<"The smallest number is: "<<c<<endl;
cout<<"The greater number is: "<<d<<endl;
return 0;
}

#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter numbers between 1-10."<<endl;
cin>>a;
switch(a)
{
case 1:
cout<<"I"<<endl;
break;
case 2:
cout<<"II"<<endl;
break;
case 3:
cout<<"III"<<endl;
break;
case 4:
cout<<"IV"<<endl;
break;
case 5:
cout<<"V"<<endl;
break;
case 6:
cout<<"VI"<<endl;
break;
case 7:
cout<<"VII"<<endl;
break;
case 8:
cout<<"VIII"<<endl;
break;
case 9:
cout<<"IX"<<endl;
break;
case 10:
cout<<"X"<<endl;
break;
default:
cout<<"Wrong Entry.";
break;
}
}

#include<iostream>
using namespace std;
int main()
{
int months,days,year;
cout<<"Enter a Month(1-12): "<<endl;
cin>>months;
if(months<=1 || months>=12)
{
cout<<"Wrong Entry."<<endl;
}
cout<<"Enter number of days: "<<endl;
cin>>days;
if(days <=1 || days>=31)
{
cout<<"Wrong Entry."<<endl;
}
cout<<"Enter two digit number of year: "<<endl;
cin>>year;
if(year<=1 || year>=99)
{
cout<<"Wrong entry.";
}
if(months*days==year)
{
cout<<"The date is magic.";
}
else
{
cout<<"The date is not magic.";
}
}

#include<iostream>
using namespace std;
int main()
{
float a,b,c,d,area1,area2;
cout<<"Rectangle 1: "<<endl;
cout<<"Enter the lenghth: "<<endl;
cin>>a;
cout<<"Enter the width: "<<endl;
cin>>b;
cout<<"Rectangle 2: "<<endl;
cout<<"Enter the length: "<<endl;
cin>>c;
cout<<"Enter the width: "<<endl;
cin>>d;
area1=a*b;
area2=c*d;
if(area1>area2)
{
cout<<"Rectangle 1 is greater than Rectangle 2."<<endl;
}
else if(area1<area2)
{
cout<<"Rectangle 2 is greater than Rectangle 1."<<endl;
}
else if(area1=area2)
{
cout<<"Rectangle 1 is equal to rectangle 2.";
}
return 0;
}

#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"\n ___________________________________\n"
<<"\n Books Purchased points earned \n"
<<"\n ___________________________________\n";
cin>>a;
if(a==0)
{
cout<<" "<<a<<" 0 "<<endl;
}
else if(a==1)
{
cout<<" "<<a<<" 5 "<<endl;
}
else if(a==2)
{
cout<<" "<<a<<" 15 "<<endl;
}
else if(a==3)
{
cout<<" "<<a<<" 30 "<<endl;
}
else if(a>=4)
{
cout<<" "<<a<<" 60 "<<endl;
}
cout<<"\n_________________________\n";
return 0;

#include<iostream>
using namespace std;
int main()
{
float a,b;
cout<<"Enter the mass of object: ";
cin>>a;
b=a*9.8;
cout<<"Weight: "<<b<<endl;
if(b>1000)
{
cout<<"It is Too heavy.";
}
else if(b<10)
{
cout<<"The object is too light.";
}
return 0;
}

#include<iostream>
using namespace std;
int main()
{
const int secondsperday=86400;
const int secondsperhour=3600;
const int secondsperminute=60;
int seconds,day,hour,mint;
cout<<"Enter Number of seconds: ";
cin>>seconds;
if(seconds>=secondsperday)
{
day=seconds/secondsperday;
cout<<" Number of days in that many seconds are: "<<day;
}
else if(seconds>=secondsperhour)
{
hour=seconds/secondsperhour;
cout<<" Number of hours in that many seconds are: "<<hour;
}
else if(seconds>=secondsperminute)
{
mint=seconds/secondsperminute;
cout<<" Number of minutes in that many seconds are: "<<mint;
}
return 0;
}

#include<iostream>
#include <cstdlib> // For rand() and srand()
#include <ctime> // For time()
using namespace std;
int main()
{

int num1,num2,answer;
num1=rand() % 41+10;
num2=rand() % 41+10;
cout<<"Solve this problem: ";
cout<<" "<<num1<<endl;
cout<<"+ "<<num2;
cout<<"_____"<<endl;
cout<<"Enter your answer";
cin>>answer;
if(num1+num2==answer)
{
cout<<"Congratulations your answer is correct.";
}
else
{
cout<<"Your answer is not correct.";
}

#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter the number of units: ";
cin>>a;
if(a>=10 && a<=19)
{
a=99-(99*20/100);
cout<<"Total cost"<<a<<"$";
}
else if(a>=20 && a<=49)
{
a=99-(99*30/100);
cout<<"Total cost: "<<a<<"$";
}
else if(a>=50 && a<=99)
{
a=99-99*40/100;
cout<<"Total cost: "<<a<<"$";
}
else if(a>100)
{
a=99-(99*50/100);
cout<<"Total cost: "<<a<<"$";
}
}

#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"Enter the amount of checks written past month: ";
cin>>a;
if(a<20)
{
cout<<"Bank's Fees for month: "<<0.10*a<<"$";
}
else if(a>=20 && a<=39)
{
cout<<"Bank's Fees for month: "<<0.08*a<<"$";
}
else if(a>=40 && a<=59)
{
cout<<"Bank's Fees for month: "<<0.06*a<<"$";
}
else if(a>=60)
{
cout<<"Bank's Fees for month: "<<0.04*a<<"$";
}
else
{
cout<<"Wrong Entry.";
}
}

#include<iostream>
using namespace std;
int main()
{
int a,b,c,d,e,f;
cout<<"Geometry Calculator\n";
cout<<"1. Calculate the area of a circle."<<endl;
cout<<"2. Calculate the area of a rectangle."<<endl;
cout<<"3. Calculate the area of a triangle."<<endl;
cout<<"4. Quit"<<endl;
cin>>a;
switch(a)
{
case 1:
{
cout<<"Enter the radius of Circle: ";
cin>>b;
cout<<"The area of circle is: "<<3.14*b*b;
break;
}
case 2:
{
cout<<"Enter the length and width of rectangle: ";
cin>>c>>d;
cout<<"The area of rectangle is: "<<c*d;
break;
}
case 3:
{
cout<<"Enter the base and height of triangle: ";
cin>>e>>f;
cout<<"The area of triangle is: "<<0.5*e*f;
break;
}
case 4:
{
cout<<"Program Ending.";
break;
}
default:
{
cout<<"Wrong entry.";
break;
}
}
}

You might also like