Question

In: Computer Science

C code only, not C++ or anything else // This program accepts the chest size from...

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.

Solutions

Expert Solution

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


Related Solutions

modify the code below to create a GUI program that accepts a String from the user...
modify the code below to create a GUI program that accepts a String from the user in a TextField and reports whether or not there are repeated characters in it. Thus your program is a client of the class which you created in question 1 above. N.B. most of the modification needs to occur in the constructor and the actionPerformed() methods. So you should spend time working out exactly what these two methods are doing, so that you can make...
C++: Write correct C++ code for a nested if-else if-else structure that will output a message...
C++: Write correct C++ code for a nested if-else if-else structure that will output a message based on the logic below. A buyer can pay immediately or be billed. If paid immediately, then display "a 5% discount is applied." If billed, then display "a 2% discount is applied" if it is paid in 30 days. If between 30 and 60 days, display "there is no discount." If over 60 days, then display "a 3% surcharge is added to the bill."...
C++ ONLY WITH COMMENTS Question: Producer / Consumer Create a program where the application accepts 2...
C++ ONLY WITH COMMENTS Question: Producer / Consumer Create a program where the application accepts 2 arguments form the command line. The first one is a number where it is a producer of threads and the second one is number of consumer threads. You are allowed to use vector as a buffer and if so then please consider it as the buffer infinite. The producers will create the widgets and will put them on the buffer however the consumer will...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose...
Write a C++ program that accepts a positive integer number from the keyboard . The purpose of the program is to find and the display all the square pair numbers between 1 and that number. The user should be able to repeat the process until he/she enters n or N in order to terminate the process and the program. Square numbers are certain pairs of numbers when added together gives a square number and when subtracted also gives a square...
2) Write a C++ program that accepts a sentence as an input from the user. Do...
2) Write a C++ program that accepts a sentence as an input from the user. Do the following with the sentence. Please use C++ style string for this question. 1) Count the number of letters in the input 2) Change all lower case letters of the sentence to the corresponding upper case
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
In C++, write a program that accepts a text file of ASCII words from standard input...
In C++, write a program that accepts a text file of ASCII words from standard input and store them and the amount of times the word appears in the file in a hash table using external chaining. Then print the words and their counts sorted based on alphabetical order and print them again in decreasing numerical order based on the amount of times the word appears in the file. Space, tab, and new line all count as space characters. The...
C++ Write a function that accepts an array of doubles and the array's size as arguments....
C++ Write a function that accepts an array of doubles and the array's size as arguments. The function should display the contents of the array to the screen.
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
C++: Do not change anything in the supplied code below that will be the Ch16_Ex5_MainProgram.cpp except...
C++: Do not change anything in the supplied code below that will be the Ch16_Ex5_MainProgram.cpp except to add documentation. PLEASE DO NOT CHANGE THE CODE JUST ADD DOCUMENTATION. Thank you. The last few have changed the code. Appreciate you all. Please use the file names listed below since your file will have the following components: Ch16_Ex5_MainProgram.cpp - given file //22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999 #include <iostream> #include...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT