Question
Programming language C
The third picture is the code that is being refactored
Student 1:10 PM 3296.- Function Specifications [15 points 5 bonus points Use appropriate loops to ensure that if the user enters on incorrect value (out-of-range) mare hece-for an input, that the user is given an accurate messoge and provided an opportunity te enter the value egain (fer every input) Use an appropriate loop to allow the user to execute the program over and over again up to ten times without having to relounch it. Store the output[s) of your progrom (such as calories) into an appropriately named arrays) After eoch iteration, the user should be provided an option to exit the program When the user indicates that she wonts to exit, the results that were stored in the anray are printed on the output screen, before the program exits Bonus: [5 points] Credits Eondhen Bea Is there a required upper linit for how many times o user con fail et each input? Eg if the user has repeatedly failed at an input attempt fer, say 10 times, the progrom exit autameticaly as way to prevent bos Answer It is a good idea, but met required. Feel free to implement it if you are o perfectionist Classify your outputs into categories and inform user about the category to which the out belongs. Eg Low, Medium and High (for calories). Try to find known averages (provide reference) to establish your decisien points for categonization Design Specification Implementation Notes Credits St ng Pennant Professor mentioned changing the user char input to upper-case automaticolly. Using the functions and We con de this by utilizing the # include ctype.hlibrary. Examale #include <ctype.h> int main letter- toupper (letter)a returs 0 Question: Credits: dntonig Rosales Team F18 I am trying to figure eout how to uhilize a leop while also giving the user a message thet they have entered an invalid value before the loop storts agoin I am using the do-while loop becouse that satisfies the function spec for the user to be able to enter the value over and over again. But there deesnt seem te be a way to include an invalid value message before the leap starts again. Anyone figure out how to de this yet? Here is an example of the loop Im using for that input: do 1 printtiPlease enter youE Height,in inches
Student 1:10 PM 32% і Example # include int main <etype.h> etter-toupper (letter) return 0: Question: Credits: dntania Bosales Team F18 I on trying to figure out how to utilize a loop while also giving the user a message thet they have entered an invalid value before the loop starts agoin I am using the do-while loop becouse that satisfies the function spec for the user to be oble to enter the value over and over again But there deesnt seem to be a way to include an invalid value message before the leap starts again. Anyone figure out how to de this yet? Here is an example of the loop Im using for that input: do i printtiPlease enter youE Height,in inches printf( between 6d and %d.,KINHEIGHT, MAX HEIGHT); - ㅏ while(Height<MIN HEIGHT 11 iHeight >MAX HEIGHTh1 - - Answer: Great way of asking a question 2. Acknowledging that you wont to go beyond what was discussed in the class. Here is one way of deing that (there are mony others) do I prinetiPlease enter youz Beight.in inehes. printfi between id and dIN HEIGHT, MAX HETGHT scanf ld,Reight ituïteigh CHIN-HEIGHT 11 İHeightXAX HEIGHT printf Incorrect entry. Please try againin Another technique printf Please enter your Reight, in inches printf( between %d and %d:); seant Iid, eight) Notioe 3 changed to while loop now whileisaleight«NIN-HEIGHT 11 İHeight >MAX-HEIGHT){ printtlIncozzeet entzy. Please tey agan) printfl Please enter your Weight,in inches.Y printl between id and id: KIN HESGHT,AX NEEGHT scantiМ., 41Heighti
https//portaleng ed Sohtior an. X | G Sprint 2:51 AM A https://drive.google.com/drive/folders/ 1BEGahwnozxtypaMoGNDRWORLIK2R t/index.html./desktop Open with Drive Notepad finclude <stdio.h> # include<stdlib.h> void getcalories (int steps, int weight) Eloat calories-1968.76 324.229 (steps 1.0/2250) 22.947 weight printf(sf, calories) int mainO printe(This program wili calculate the ssount of calozies burned when taking x number of steps while walkingn) int atep 5 = 0; to search
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include<stdio.h>
#include<stdlib.h>
#define MAX_LIMIT 10
void getCalories(int steps,int weight)
{
float calories= -1968.76 - 324.229*(steps*1.0/2250)*22.947*weight;
printf("%f",calories);
}

int main()
{
printf("This program will calculate the amount of calories burnes while taking x number of steps while walking\n");
int c;
do
{
printf("Enter steps and weight ");
int steps=0;
int weight=0;

scanf("%d",&steps);
scanf("%d",&weight);

int error=0;
int counter=0;
while(steps<0 || weight<=0) //wrong input
{
counter++;
printf("Wrong input. Trial remaing %d\n",MAX_LIMIT-counter);

if(counter>=MAX_LIMIT)
{
error = 1;
break;
}
printf("Enter steps and weight ");
scanf("%d",&steps);
scanf("%d",&weight);

}

if(error)
{
printf("You have crossed the number of invalid attempts\n");
break;
}

getCalories(steps,weight);

printf("\ntype 0 to exit / any number to continue");
scanf("%d",&c);

}while(c);

return 0;
}

OUTPUT:

Dİ HACodeBlockslfile:DS\Untitled4.exe This program will calculate the amount of calories burnes while taking x number of steps while walking Enter steps and weight 60 60 13872.892578 type e to exit / any number to continue 1 Enter steps and weight 30 65 8416.832031 type e to exit / any number to continue 1 Enter steps and weight -8 60 Wrong input. Trial remaing 9 Enter steps and weight -9 61 Wrong input. Trial remaing 8 Enter steps and weight 0 Wrong input. Trial remaing 7 Enter steps and weight 21 e Wrong input. Trial remaing Enter steps and weight -7 65 Wrong input. Trial remaing 5 Enter steps and weight -9 66 Wrong input. Trial remaing 4 Enter steps and weight -12 65 Wrong input. Trial remaing 3 Enter steps and weight -88 66 Wrong input. Trial remaing 2 Enter steps and weight θ θ Wrong input. Trial remaing 1 Enter steps and weight -9 56 wrong input. Trial remaing 0 You have crossed the number of invalid attempts 6 Process returned 0 (Θχ0) execution time : 81.909 s Press any key to continue

please provide positive feedback if it helped

Add a comment
Know the answer?
Add Answer to:
Programming language C The third picture is the code that is being refactored Student 1:10 PM...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is done in c programming and i have the code for the programs that it wants at the bottom i ...

    This is done in c programming and i have the code for the programs that it wants at the bottom i jut dont know how to call the functions Program 2:Tip,Tax,Total int main(void) {    // Constant and Variable Declarations    double costTotal= 0;    double taxTotal = 0;    double totalBill = 0;    double tipPercent = 0;    // *** Your program goes here ***    printf("Enter amount of the bill: $");    scanf("%lf", &costTotal);    printf("\n");    // *** processing ***    taxTotal = 0.07 * costTotal;    totalBill...

  • Write a program that asks the user to type an even number or 111 to stop....

    Write a program that asks the user to type an even number or 111 to stop. When the user types an even number, display the message “Great Work”, and then ask for input again. When the user types an odd number, display the message “Try again” and ask the user to enter again. When the user enters the sentinel value of 111 the program ends I've attempted this but it went horribly wrong. we are only suppose to use while,...

  • In C programming language: This program will output a right triangle based on user specified height...

    In C programming language: This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or *....

  • IT Java code In Lab 8, we are going to re-write Lab 3 and add code...

    IT Java code In Lab 8, we are going to re-write Lab 3 and add code to validate user input. The Body Mass Index (BMI) is a calculation used to categorize whether a person’s weight is at a healthy level for a given height. The formula is as follows:                 bmi = kilograms / (meters2)                 where kilograms = person’s weight in kilograms, meters = person’s height in meters BMI is then categorized as follows: Classification BMI Range Underweight Less...

  • the coding language is just the basic c language and here is my first attempt at...

    the coding language is just the basic c language and here is my first attempt at this problem my problem is that if the user inputs a number that is equal to a number that has been entered previously the code will never end until the user enters a number that is bigger than any other number previously entered any help will be helpful Write a program to read-in a sequence of integers from the keyboard using scanf(). Your program...

  • Having trouble with the do while/while loop and the switch statement. I got some of the...

    Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...

  • Java Programming Language Edit and modify from the given code Perform the exact same logic, except...

    Java Programming Language Edit and modify from the given code Perform the exact same logic, except . . . The numeric ranges and corresponding letter grade will be stored in a file. Need error checking for: Being able to open the text file. The data makes sense: 1 text line of data would be 100 = A. Read in all of the numeric grades and letter grades and stored them into an array or arraylist. Then do the same logic....

  • Step 4: Add code that discards any extra entries at the propmt that asks if you...

    Step 4: Add code that discards any extra entries at the propmt that asks if you want to enter another score. Notes from professor: For Step 4, add a loop that will validate the response for the prompt question:       "Enter another test score? (y/n): " This loop must only accept the single letters of ‘y’ or ‘n’ (upper case is okay). I suggest that you put this loop inside the loop that already determines if the program should collect...

  • Please I need help in C language, I am trying to modify the code per the...

    Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions:                  1.      First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....

  • Working in C, modify the algorithm created in the Topic 1 assignment "Non-Linear Flow Chart" to...

    Working in C, modify the algorithm created in the Topic 1 assignment "Non-Linear Flow Chart" to instead compute the nth term in the series by calling a recursive function. Note that the value of "n" will need to be an input argument, along with the two starting values of the series. Discuss the efficiency of this method versus the iterative logic that you wrote previously. Previous Code: //main.c #include<stdio.h> #include<limits.h> int main() {    //declare a integer data type variales...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT