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

The program has to be written in C language. keep it simple, please. DECISION ST

ID: 3587890 • Letter: T

Question

The program has to be written in C language. keep it simple, please.

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.

Explanation / Answer

/******************************************grocesary.c*******************************************/

#include<stdio.h>

#include <string.h>

#include <stdlib.h>

int main(int argc, char *argv[])

{

// variable declaration

int i,j=2;

int num1,num2,num3,total;

// checking number of argument

if( argc < 4 || argc > 4) {

printf("usage: ./a.out followed by 3 numbers ");

return 1;

}

// conversion string to integer

num1 = atoi(argv[1]);

num2 = atoi(argv[2]);

num3 = atoi(argv[3]);

//calculating total

total = num1+num2+num3;

if(total<50) {

printf("Amount Spent $%d, you must be starving ",total);

} else if(total>=50 && total<200) {

printf("Amount Spent $%d, you are eating well ",total);

} else if(total>=200 ) {

printf("Amount Spent $%d, you are going to get fat ",total);

}

// checking which week you are spending more

if(num1<num2) {

printf("You are eating more? ");

}

if(num2>num3 && num1 > num3) {

printf("You are on diet ");

}

// displaying average amount on groceries eacch week

printf("Average amount spent on week1: $%.2f ",((float)num1/7));

printf("Average amount spent on week2: $%.2f ",((float)num2/7));

printf("Average amount spent on week3: $%.2f ",((float)num3/7));

return 0;

}

/**********************************output*******************************/

C:UserslmaliDesktopChegg>g++ grocesary.c

C:UserslmaliDesktopChegg>a.exe 20 30 10
Amount Spent $60, you are eating well
You are eating more?
You are on diet
Average amount spent on week1: $2.86
Average amount spent on week2: $4.29
Average amount spent on week3: $1.43

Thanks a lot. Please let me know if you have any doubt.