Write a program, named lab02_p1.cpp, that reads three integers from the keyboard
ID: 3706345 • Letter: W
Question
Write a program, named lab02_p1.cpp, that reads three integers from the keyboard and store the values into variables a, b, and c. Implement the instructions to compute the average of the three values and store the value into variable d. The program will print the values of each variables (a, b, c, and d). Example output s./lab02_pl Input value for A: 2 Input value for B: 11 Input value for C: 6 The average of 2, 11, 6 is 9.66666666667 Extra Credit A customer in a store is purchasing five items. The prices of the five items are: Price of item 1 = $12.95 Price of item 2 $24.95 Price of item 3 $6.95 Price of item 4 $14.95 Price of item 5 $3.95 Write a program, named lab02_p2.cpp, that holds the prices of the five items in five variables. Display each item's price, the subtotal of the sale, the amount of sales tax, and the total. Assume the sale tax is 11%Explanation / Answer
#include <stdio.h>
int main()
{
int a,b,c,d;
printf("Input value for A: ");
scanf("%d", &a);
printf("Input value for B: ");
scanf("%d", &b);
printf("Input value for C: ");
scanf("%d", &c);
d = a+ b + c;
printf("The avergae of %d, %d, %d is %lf ",a,b,c ,(d/3.0));
return 0;
}
Output:
#include <stdio.h>
int main()
{
double i1,i2,i3,i4,i5, subtotal , salesTax, total;
printf("Price of item 1: ");
scanf("%lf", &i1);
printf("Price of item 2: ");
scanf("%lf", &i2);
printf("Price of item 3: ");
scanf("%lf", &i3);
printf("Price of item 4: ");
scanf("%lf", &i4);
printf("Price of item 5: ");
scanf("%lf", &i5);
subtotal = i1+i2+i3+i4+i5;
salesTax = (subtotal*11)/100.0;
total = salesTax + subtotal;
printf("Five items: ");
printf("%lf %lf %lf %lf %lf ",i1,i2,i3,i4,i5);
printf("Sub Total: %lf ", subtotal);
printf("Sales Tax: lf ", salesTax);
printf("Total: %lf ", total);
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.