Question

program that does the following exactly once: int W e a complete C program that does the • Uses a user validation loop to pro

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C-Code

Explaination  

Note (point 1 and 3 are important )

1. Main point where you might get stuck is how to ensure that user is entering a non-negative number so i uses a while loop which run until until user is entering a negative number .

2. Calculate avg i.e n/30;

3. Now one point ot look into here question says to take input into a variable of int type and avg we want in point so we will take it float but here when we do divide n/30 so to get ans is float we need to type case n into float for getting proper results

so i did float avg=(float)n/30;

4. Then simply apply if - else and write required printf statements

Code is

 #include<stdio.h> int main() { int n; printf("Enter number of hamburgers eaten in (30 days) :" ); scanf("%d",&n); while(n<0)// will run until user enters a non-negative number { printf("Enter number of hamburgers eaten in (30 days) :" ); scanf("%d",&n); } float avg; avg= (float)n/30; // type casting n to get float ans for avg printf("\nThe number of hamburgers eaten per day was %.1f \n",avg); if(avg >0.5) { printf("That is a lot of burgers \n"); } else if(avg==0.0) { printf("I don't believe you \n"); } else { printf("That's sound reasonable \n"); } } 

Input

#include<stdio.h> int main() int n; printf (Enter number of hamburgers eaten in (30 days) : ); scanf(%d, &n); while (no)Output for run 1

- O X C:\Users\Sudhanshu Goel\Desktop\ces3 c programing\hamburgers.exe Enter number of hamburgers eaten in (30 days) :-10 E

Output for Run 2

- 0 x C:\Users\Sudhanshu Goel\Desktop\ces3 c programing\hamburgers.exe Enter number of hamburgers eaten in (30 days) :0 The

Output for Run 3

- O X C:\Users\Sudhanshu Goel\Desktop\ces3 c programing\hamburgers.exe Enter number of hamburgers eaten in (30 days) :12 Th

Thank You

'If u like the answer please do rate it i will feel good and for any doubts comment the answer

Add a comment
Know the answer?
Add Answer to:
program that does the following exactly once: int W e a complete C program that does...
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
  • Create a modular program using structured programming to store the amount of money a local store...

    Create a modular program using structured programming to store the amount of money a local store made in sales for each day of the past week. The user will be given the option to enter an amount for the next day, compute the average, find the highest amount, find the lowest amount, or print all the information including the daily sales with the average, highest, and lowest amount. When the user chooses an option to enter an amount for the...

  • In python using a def main() function, Write a function that will print a hello message,...

    In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a...

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

  • Write a C++ program that does the following: Asks the user to enter 3 integers, Obtains...

    Write a C++ program that does the following: Asks the user to enter 3 integers, Obtains the numbers from the user, Prints the largest number and then the smallest of the numbers, If the numbers are equal, prints the message: "These numbers are equal." Prints the sum, average, and product of the 3 numbers.

  • This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named...

    This interactive program focuses on if/else statements, Scanner, and returning values. Turn in a file named Budgeter.java. To use a Scanner for console input, you must import java.util.*; in your code. This program prompts a person for income and expense amounts, then calculates their net monthly income. Below are two example logs of execution from the program. This program’s behavior is dependent on the user input (user input is bold and underlined below to make it stand out and differentiate...

  • C Programming Quesition (Structs in C): Write a C program that prompts the user for a...

    C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...

  • C++ Given a int variable named callsReceived and another int variable named operatorsOnCall, write the necessary...

    C++ Given a int variable named callsReceived and another int variable named operatorsOnCall, write the necessary code to read values into callsReceived and operatorsOnCall and print out the number of calls received per operator (integer division with truncation will do). HOWEVER: if any value read in is not valid input, just print the message "INVALID". Valid input for operatorsOnCall is any value greater than 0. Valid input for callsReceived is any value greater than or equal to 0. Revel for...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • Write a program that will predict the size of a population of organisms. The program should...

    Write a program that will predict the size of a population of organisms. The program should ask for the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. For example, a population might begin with two organisms, have an average daily increase of 50 percent, and will be allowed to multiply for seven days. The program should use a loop to display the size of the population for each...

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