Answer to Question #116827 in C for Eugene

Question #116827
Learners at a local basic school volunteered to sell fresh baked bread to raise funds to increase
the number of computers for their computer lab. Each student reported the number of loaves of
bread he/she sold. Write a C programme that will output the total number of loaves of bread
sold, the total revenue generated by selling the bread, and the average number of loaves of bread
sold by each student. The input data is provided in the following form:
1
Expert's answer
2020-05-18T16:59:15-0400

Edit

#include <stdio.h>

int main(void) {
  // total number of students
  int totalStudents = 10;

  // number of loaves sold per student
  int loavesSold[totalStudents];

  // total number of loaves sold
  int totalLoavesSold = 0;

  // loaf price
  double loafPrice = 1.4;

  // ask user to enter number of loaves sold for each students
  for (int i = 0; i < totalStudents; ++i) {
    printf("Enter number of sold loaves for student #%i: ", i+1);
    scanf("%i", &loavesSold[i]);

    // calculate total
    totalLoavesSold += loavesSold[i];
  }

  // print total number
  printf("Total number sold: %d\n", totalLoavesSold);

  // print revenue
  printf("Revenue: %.2f\n", totalLoavesSold * loafPrice);

  // print average number
  printf("Average number: %d\n", totalLoavesSold / totalStudents); 

  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS