Create program using appropriate control structure.
Position Discount
1. Food Item 5 %
2. Health Item 6%
3. Electric Item 9%
4. Cloth Item 4 %
2. Write a program that prompts the user to input two number and symbol ( + , - , * , /). The program should then output the number and message saying result of the operation.
#include <iostream>
using namespace std;
int main()
{
int count1, count2, count3, count4;
double price1, price2, price3, price4, total;
cout<<"Enter count food and price food: ";
cin >> count1>>price1;
cout<<"Enter count health and price health: ";
cin >> count2>>price2;
cout<<"Enter count electric and price electric: ";
cin >> count3>>price3;
cout<<"Enter count cloth and price cloth: ";
cin >> count4>>price4;
total=count1*price1*(100-5)/100+count2*price2*(100-6)/100+count3*price3*(100-9)/100+count4*price4*(100-4)/100;
cout << "total: " << total;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
double num1, num2, result;
char t;
cout<<"Enter two numbers and operator(*/+-)";
cin>> num1>> num2>>t;
if (t=='*')
result=num1*num2;
if (t=='/')
result=num1/num2;
if (t=='-')
result=num1-num2;
if (t=='+')
result=num1+num2;
cout << "result = " << result;
return 0;
}
Comments
Leave a comment