Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 7 8 marks Sarah and John are doing a car boot sale to raise money for a

ID: 3704490 • Letter: Q

Question

Question 7 8 marks Sarah and John are doing a car boot sale to raise money for a charity. Write a program that helps them to keep track of each one's sale. The program should allow them to enter a character code which should be either 'S' or 'J' and then the sales amount. This should repeat and the loop should stop when a character other than "S' or 'J' is entered for the code. The program should print the total sales for each person before it exits. To make it easy for Sarah and John the character code should be accepted even if it is entered in lower case. Submit the program and output. Enter nane code: amount of the itom: R56. 75 Enter sales Enter name code Enter sales amount of the item: R20 Enter name code Enter sales amount of the itom: R90 Enter name code Total sales by Sarah: R90.00 Total sales by John: R76. 75 Process returned 0 (0x0) execution time: 32,238 ress any key to continue

Explanation / Answer

Solution for question 7 :

# include <stdio.h> // library for printf ...

int main(void) {

char name_code; // name_code

float sarah_sales = 0.0; // sarah sale amount

float john_sales = 0.0; // john sale amount

float item_amount; // new item value

printf("Enter name code : "); // Read name code

scanf("%c", &name_code);

while (name_code == 'j' || name_code == 'J' || name_code == 's' || name_code == 'S') { // Condition on name_code

printf("Enter sales amount of the item : "); // Read the value of item sold

scanf("%f", &item_amount);

if (name_code == 'j' || name_code == 'J') // For John

john_sales = john_sales + item_amount;

else if (name_code == 's' || name_code == 'S') // For Sarah

sarah_sales = sarah_sales + item_amount;

printf("Enter name code : "); // Overwrite name code to read in a loop

scanf("%c", &name_code);

}

// Print the results

printf("Total sales by Sarah : R %.2f ", sarah_sales);

printf("Total sales by John : R %.2f ", john_sales);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote