In: Computer Science
C code only, not C++ or anything else
// This program accepts the chest size from the customer
// and returns the proper shirt size as well as the price.
// function prototype
void check_size_price(int size_val, char *size_char, int *price);
#include <stdio.h>
int main()
{
int chest_size; //input - entered chest size
char size_str; //output - size (S/M/L)
int p; //output - price
// validation loop for the input – the chest size must be a positive integer
// Call function "check_size_price"
// print results
printf("The size of the shirt is %c\n", size_str); fflush(stdout);
printf("and the price is $ %d \n", p); fflush(stdout);
return (0);
}
// ################################## Function
// Start your function code here
Problem Description
1. Read through the given code ( Lab06.c ).
2. The main program uses a ”helper” function check_size_price () to determine and report the proper shirt size as well as the price based on the chest size entered by the user.
3. Your task is to write the function definition for the check_size_price () function (notice that the prototype is given) as well as completing the main function in the sections related to the validation loop and calling the helper function. 4. Once you have completed your function definition and the missing parts of the code: (a) Make sure that your program compiles and runs without errors or warnings. (b) Run your program enough times to check all the cases for correctness. (c) If it runs correctly, then submit your code on Canvas for a check-off.
Code
#include <stdio.h>
void check_size_price(int size_val, char *size_char, int *price);
int main()
{
int chest_size; //input - entered chest size
char size_str; //output - size (S/M/L)
int p; //output - price
// validation loop for the input – the chest size must be a positive integer
do{
printf("\nEnter chets size (must be >0) : ");
scanf("%d",&chest_size);
}while(chest_size<=0);
// Call function "check_size_price"
check_size_price(chest_size, &size_str, &p);
// print results
printf("The size of the shirt is %c\n", size_str); fflush(stdout);
printf("and the price is $ %d \n", p); fflush(stdout);
return (0);
}
void check_size_price(int size_val, char *size_char, int *price){
if(size_val<=25){
*size_char='S';
*price=100;
}
if(size_val<=35){
*size_char='M';
*price=200;
}
else{
*size_char='L';
*price=300;
}
}
Screenshot
Output