I realize my code is kinda shitty but for my intro to C, I need to edit this to
ID: 3906012 • Letter: I
Question
I realize my code is kinda shitty but for my intro to C, I need to edit this to contain the 6 function definitions/calls. I have zero idea how to code properly please help.( function calls at the bottom)
/******************
HW2
date: 05-31-18
******************/
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int steps;
double weight;
double calories;
//function is the number of steps multiplied by 1/20
//1 calorie burned per 20 steps
double calculateCaloriesBurned; // calculates the amount of calories burned
int weightcheck; // to check if the weight is a possible value
int main(void)
{
//banner and functions
double weight; weight = 0;
double steps; steps = 0;
double calories;
printf("Hello and welcome to fau fittness app! ");
// gets the steps and returns as a check
printf("can you please enter how many steps you have taken today...");
scanf(" %lf", &steps);
if (steps < 0 || steps > 50000) {
printf("please enter a valid number of steps ");
scanf("%lf", &steps);
}
printf("%4.0f. ", steps);
// gets the weight and returns as a check
printf("can you please enter your weight ");
scanf(" %lf", &weight);
if (weight < 55 || weight >350) {
printf("please enter a valid weight ");
scanf("%lf", &weight);
}
printf(" %4.0f ", weight);
calories = steps*0.05;
printf("You have burn %4.0f calories ", calories);
return 0;
}
==============================================
void banner();
This function prints a friendly message to the user,
informing her that your specific application is running.
void getInputs();
This function will obtain all the values of all input variables you need from the user. Note that the signature shown above does not show the output parameters, you will need. The number of parameters depends on the parameters you will obtain from the user.
calculateOutputs();
This function will take in all “inputs” as input parameters and provide outputs to the calling function. If you have only one output, it is ok to use “return -- Option 2”, in which case the return type will not be void. If you have more than two outputs, you will need to use Option 1 (use more parameters that are pointers), in which case the return type will be void. In either case the return value(s) must be finally stored in variable(s), and array(s) of test() function.
void printOne();
This function will display the results of a single execution of the code.
Therefore it must take all inputs and all outputs as “input parameters”. b
void printAll(double/int* array, int size);
This function will display the contents of the array that contains results of all executions in a friendly manner.
void test();
Throughout the development process, you must built test code inside the test function. This is critical to seek help. Help for code that is not properly tested will be delayed.
Explanation / Answer
SOlution:
#include<stdio.h>
//Function Prototypes
void banner();
void getInputs();
double calculateOutputs(int);
void printAll(double);
void test();
//Declaring global variables
int steps;
double weight;
int main(){
test();//Calling test function to test our program.
return 0;
}
//Displaying a welcome message to the user.
void banner(){
printf("Hello and welcome to the fitness app! ");
}
//Getting inputs from the user.
void getInputs(){
//Continuously asking for the steps until and unless user types in a valid number of steps.
while(1){
printf("Please enter how many steps you have taken today... ");
scanf("%d", &steps);
//Checking for the valid steps if not then asking the steps again
if (steps < 0 || steps > 50000) {
//Displaying error message for invalid steps
printf("Please enter a valid number of steps. ");
continue;
}else{
break;
}
}
//Continuously asking for the steps until and unless user types in a valid weight.
while(1){
printf("Please enter your weight. ");
scanf("%lf", &weight);
//Checking for the valid weight if not then asking the weight again
if (weight < 55 || weight > 350) {
//Displaying error message for invalid weight
printf("please enter a valid weight. ");
continue;
}else{
break;
}
}
}
//Calculating calories.
double calculateOutputs(int steps){
//function is the number of steps multiplied by 1/20
//1 calorie burned per 20 steps
double calories = steps*0.05;
return calories;
}
//Printing the result
void printAll(double calories){
printf("You have burnt %.2lf calories. ", calories);
}
//Test function to test our program
void test(){
//Calling banner to display the message
banner();
//Calling takeInputs to take input form the user.
getInputs();
//Calling CalculateOutputs to calculate calories
double calories = calculateOutputs(steps);
//Calling PrintAll to print the result.
printAll(calories);
}
Sample Run:
Hello and welcome to the fitness app!
Please enter how many steps you have taken today...
-3
Please enter a valid number of steps.
Please enter how many steps you have taken today...
200
Please enter your weight.
40
please enter a valid weight.
Please enter your weight.
60
You have burnt 10.00 calories.
Note: It seems to be you are very new to the C. I wish you all the best for learning C, it's very easy to understand just think like a compiler, or maybe your teacher is not teaching you in a good manner. If you have any doubt comment me below before giving negative feedback and if you really liked the code then do give a big thumbs up. You can reach out to me for any help in C,C++, Java and python and web development too at subratbehera94@g.com.