Write a program so that if the clerk enters the number of miles, the program would display the total price owed.
solution of above question....
#include<iostream>
using namespace std;
int main()
{
double milage,price,pricemorethan100,rate,milagemorethan100;
cout<<"Enter the Milage = ";
cin>>milage;
if(milage<=100)
{
price = milage * 0.25;
cout<<"The Gasolone bill is = $ "<<price<<endl;
}
else if(milage>100)
{
milagemorethan100 = milage - 100;
pricemorethan100 = milagemorethan100 * 0.15;
price = 100 * 0.25;
rate = price + pricemorethan100;
cout<<"The gasoline bill is = $ "<<rate<<endl;
}
return 0;
}
____________________________________________________________________________
Q # 2: Find maximum of three numbers...
The solution is:
Q # 3: Make a basic calculator using else if:
#include<iostream>
using namespace std;
int main()
{
double milage,price,pricemorethan100,rate,milagemorethan100;
cout<<"Enter the Milage = ";
cin>>milage;
if(milage<=100)
{
price = milage * 0.25;
cout<<"The Gasolone bill is = $ "<<price<<endl;
}
else if(milage>100)
{
milagemorethan100 = milage - 100;
pricemorethan100 = milagemorethan100 * 0.15;
price = 100 * 0.25;
rate = price + pricemorethan100;
cout<<"The gasoline bill is = $ "<<rate<<endl;
}
return 0;
}
____________________________________________________________________________
Q # 2: Find maximum of three numbers...
The solution is:
#include<iostream>
using namespace std;
int main()
{
int n1,n2,n3;
cout<<"Enter three Numbers ";
cin>>n1>>n2>>n3;
if(n1 > n2 && n1 > n3)
{
cout<<" Number1 is Maximum"<<endl;
}
else if(n2 > n1 && n2 > n3)
{
cout<<" Number2 is Maximum"<<endl;
}
else if(n3 > n2 && n3 > n1)
{
cout<<"Number3 is Maximum"<<endl;
}
else if(n1==n2 && n1>n3)
{
cout<<"number 1 and number 2 are equal but greater than number3."<<endl;
}
else if(n2==n3 && n2>n1)
{
cout<<"number 2 and number 3 are equal but greater than number1."<<endl;
}
else if(n3==n1 && n3>n2)
{
cout<<"number 1 and number 3 are equal but greater than number2."<<endl;
}
else
{
cout<<"all three numbers are equal"<<endl;
}
return 0;
}
using namespace std;
int main()
{
int n1,n2,n3;
cout<<"Enter three Numbers ";
cin>>n1>>n2>>n3;
if(n1 > n2 && n1 > n3)
{
cout<<" Number1 is Maximum"<<endl;
}
else if(n2 > n1 && n2 > n3)
{
cout<<" Number2 is Maximum"<<endl;
}
else if(n3 > n2 && n3 > n1)
{
cout<<"Number3 is Maximum"<<endl;
}
else if(n1==n2 && n1>n3)
{
cout<<"number 1 and number 2 are equal but greater than number3."<<endl;
}
else if(n2==n3 && n2>n1)
{
cout<<"number 2 and number 3 are equal but greater than number1."<<endl;
}
else if(n3==n1 && n3>n2)
{
cout<<"number 1 and number 3 are equal but greater than number2."<<endl;
}
else
{
cout<<"all three numbers are equal"<<endl;
}
return 0;
}
_______________________________________________________________________________
Q # 3: Make a basic calculator using else if:
Solution:
#include<iostream>
using namespace std;
int main()
{
int n1,n2;
char operation;
cout<<"Enter two numbers";
cin>>n1>>n2;
cout<<"Enter Operation = ";
cin>>operation;
if(operation=='+')
{
cout<"Addition"<<n1+n2<<endl;
}
else if(operation=='-')
{
cout<<"Subtraction"<<n1-n2<<endl;
}
else if(operation=='*')
{
cout<<"Multiplication"<<n1*n2<<endl;
}
else if(operation=='/')
{
cout<<"Division"<<static_cast<double>(n1) / (n2)<<endl;
}
else if(operation=='%')
{
cout<<"Modulus"<<n1%n2<<endl;
}
else cout<<"Invalid Value"<<endl;
return 0;
}
using namespace std;
int main()
{
int n1,n2;
char operation;
cout<<"Enter two numbers";
cin>>n1>>n2;
cout<<"Enter Operation = ";
cin>>operation;
if(operation=='+')
{
cout<"Addition"<<n1+n2<<endl;
}
else if(operation=='-')
{
cout<<"Subtraction"<<n1-n2<<endl;
}
else if(operation=='*')
{
cout<<"Multiplication"<<n1*n2<<endl;
}
else if(operation=='/')
{
cout<<"Division"<<static_cast<double>(n1) / (n2)<<endl;
}
else if(operation=='%')
{
cout<<"Modulus"<<n1%n2<<endl;
}
else cout<<"Invalid Value"<<endl;
return 0;
}
No comments:
Post a Comment