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

DECISION STATEMENT (2nd assignment) You can assume that the user of this program

ID: 3847253 • Letter: D

Question

DECISION STATEMENT (2nd assignment) You can assume that the user of this program will enter three different numbers. Each number will be the price the person paid for his or her weekly groceries. If the amount is BELOW $50 then display the amount spent and the words, you must be starving. If the amount is $50 or more but less than $200 then display the amount spend and the words, you are eating well. If the amount is $200 or more then display the amount spend and the words, you are going to get fat. In addition, if the second number is greater than the first number (the first week) then write, are you eating more? If the third number is less than both of the other numbers then write, are you on a diet. Finally, display the average amount spent on groceries each week. It a C program DECISION STATEMENT (2nd assignment) You can assume that the user of this program will enter three different numbers. Each number will be the price the person paid for his or her weekly groceries. If the amount is BELOW $50 then display the amount spent and the words, you must be starving. If the amount is $50 or more but less than $200 then display the amount spend and the words, you are eating well. If the amount is $200 or more then display the amount spend and the words, you are going to get fat. In addition, if the second number is greater than the first number (the first week) then write, are you eating more? If the third number is less than both of the other numbers then write, are you on a diet. Finally, display the average amount spent on groceries each week. It a C program DECISION STATEMENT (2nd assignment) You can assume that the user of this program will enter three different numbers. Each number will be the price the person paid for his or her weekly groceries. If the amount is BELOW $50 then display the amount spent and the words, you must be starving. If the amount is $50 or more but less than $200 then display the amount spend and the words, you are eating well. If the amount is $200 or more then display the amount spend and the words, you are going to get fat. In addition, if the second number is greater than the first number (the first week) then write, are you eating more? If the third number is less than both of the other numbers then write, are you on a diet. Finally, display the average amount spent on groceries each week. It a C program

Explanation / Answer


#include <stdio.h>


void calculateAverage();

int main() {
printf("This program calculates the average amount spend on the groceries");
calculateAverage(); // calling the function calculateAverage
   return 0;

}

//method to calculate average
void calculateAverage(){
float firstWeekPrice,secondWeekPrice,thirdWeekPrice,average,innerChoice=0;//declare variables
           printf(" Please enter the three prices for weekly groceries : ");
           printf(" Please enter the first week price : ");
           scanf("%f",&firstWeekPrice);// taking input from the user
           printf(" Your have spent %.2f $ in your first week.",firstWeekPrice);
           if(firstWeekPrice<50){ // conditions to check expenditure
           printf(" You must be starving",firstWeekPrice);
           }else if(firstWeekPrice>=50 && firstWeekPrice<200){
           printf(" you are eating well");
           }else if(firstWeekPrice>=200){
           printf(" you are going to get fat");
           }
           printf(" Please enter the second week price : ");
           scanf("%f",&secondWeekPrice);
       printf(" Your have spent %.2f $ in your second week.",secondWeekPrice);
           if(secondWeekPrice<50){ // conditions to check expenditure
           printf(" You must be starving");
           }else if(secondWeekPrice>=50 && secondWeekPrice<200){
           printf(" you are eating well");
           }else if(secondWeekPrice>=200){
           printf(" you are going to get fat");
           }
           printf(" Please enter the third week price : ");
           scanf("%f",&thirdWeekPrice);
       printf(" Your have spent %.2f $ in your third week.",thirdWeekPrice);
           if(thirdWeekPrice<50){ // conditions to check expenditure
           printf(" You must be starving");
           }else if(thirdWeekPrice>=50 && thirdWeekPrice<200){
           printf(" you are eating well");
           }else if(thirdWeekPrice>=200){
           printf(" you are going to get fat");
           }

           if(secondWeekPrice>firstWeekPrice){
           printf(" Are you eating more");
           }

           if(thirdWeekPrice<secondWeekPrice && thirdWeekPrice<firstWeekPrice){
           printf(" Are you on diet");
           }
           average = (firstWeekPrice+secondWeekPrice+thirdWeekPrice)/3; // finding average
           printf(" Average expense of three weeks is : %.2f $",average);
          
}

------------------------------------------------------output------------------------------------------------------------------------