Practice the top-down approach to program design and implementation. Recall that, with this approach, we assume that any other functions on which a particular function depends operate as expected. We use stub functions as temporary placeholders when designing and implementing the program, and as we iterate, we refine these stubs by writing the C code that implements the required functionality. Create a project called Dailyl9. Add a C source file to the project named daily 19.C. Converting lengths and weights Write a program that asks the user if he or she wants to convert values that are lengths or weights. If the user chooses lengths, the program calls a stub function convert_lengths that simply indicates the user\'s choice. If the user chooses weights, the program calls a stub function convert_weights that simply indicates the user\'s choice. Use the value 1 to indicate lengths and the value 2 to indicate weights. If the user enters 0, terminate the program. The program should continue to prompt the user for input until he or she correctly enters a value of 0, 1, or 2. In addition, the program should allow the user to call convert lengths or convert weights as many times as desired (i.e., until a value of 0 is input, indicating that the user is finished). Notice that this style of loop does not require you to ask the user if they want to continue but instead assumes they want to continue until they select 0. From now on, please always write comments for each function and explain the function parameters. You should write comments for other part of your code when needed. An example output: convert lengths convert weights Exit Please choose from (1, 2, 9):1 The user wants to convert_lengths. convert lengths convert weights Exit Please choose from (1, 2, 0):2 The user wants to convert_weights. convert lengths convert weights Exit Please choose from (1, 2, 0):0 User chose to exit.
#include <stdio.h>
char* convert_lengths(); //function prototype for convert_lengths function
char* convert_weights(); //function prototype for convert_weights function
int main(void)
{
int choice;
do
{
printf(\"\ 1. convert lengths\");
printf(\"\ 2. convert weights\");
printf(\"\ 0. Exit\");
printf(\"\ Please choose from (1,2,0):\");
scanf(\"%d\",&choice); //Enter the value of choice
if(choice == 1)
{
printf(\"%s\",convert_lengths()); // if choice =1 call convert_lengths function and display the returned string
}
else if(choice ==2)
{
printf(\"%s\",convert_weights()); /// if choice =2 call convert_weights function and display the returned string
}
else if(choice ==0) //if choice =0 exit the loop
break;
}while(choice != 0);
return 0;
}
char* convert_lengths()
{
return \"\ The user wants to convert_lengths.\"; //function returning char array or string
}
char* convert_weights()
{
return \"\ The user wants to convert_weights.\"; //function returning char array or string
}
Output:
Success time: 0 memory: 2164 signal:0