Write C code to repeatedly ask the user for a number, then once the user enters 0, the code displays the min, max and average of all values entered.
To get proper credit, name the variables as listed below and follow the directions carefully. Do not use any break or similar type of statements.
To implement the above code, you will need to count the entries - name the counter variable num_count.
You will also need to use a variable, name it min_in so each time the user gives input, and the input is not 0, then compare min_in with the input, if the min_in is > input, then assign min_in to the input.
Similarly name another variable max_in, and compare it to the input, but assign max_in to the input only if max_in is < input.
To calculate the average, accumulate each input into a variable, total. Then after the loop the average is the total divided by the number of entries.
Once the loop is over, display the calculated values (min, max and the average) with a proper wording in three lines. The input is not restricted to integer value so declare the variables above with a proper type. Show the output using two decimal places, and align the three output values as in this sample output:
The minimum entry was: 2.30
The maximum entry was: 62.51
The average of all entries was: 52.81
Code:
#include<stdio.h>
//header files including
int main()
{
int num_count=0;
//num_count variable for counting the entries
float input_number,min_in,max_in,total;
//input_number,min_in,max_in,total variables
printf("Enter a Number : ");
scanf("%f",&input_number);
//taking input from
user
while(input_number!=0)
//itearte the loop until the
input number is equal to zero
{
if(num_count==0)
//if
num_count=0 means for first number make that as minimum and maximum
and add it to total
{
min_in=input_number;
//assign input number as
minimum
max_in=input_number;
//assign input as
maximum
total=total+input_number;
//adding input number to total
}
else
//else case
{
if
(min_in>input_number)
//checking the input is less
than existing minimum value or not
min_in=input_number;
//if yes
store that value into min_in
if
(max_in<input_number)
//checking the input is
greater than existing maximum value or not
max_in=input_number;
//if yes
store that value into max_in
total=total+input_number;
//add input_number to
total
}
num_count++;
//input_number count will increase used for average
calculation
printf("Enter a Number :
"); //asking user
to enter the number repeatedly
scanf("%f",&input_number);
}
printf("The minimum entry was:
%.2f\n",min_in);
//finally printing the minimum value of
entries
printf("The maximum entry was:
%.2f\n",max_in);
//maximum value of entries
printf("The average of all entries was:
%.2f\n",(total/num_count));
//average value calculated by total/num_count
all are rounded to two decimals
return 0;
}
Code screenshots and output:
Note: if you have any queries please post a comment thanks a lot...always available to help you
Write C code to repeatedly ask the user for a number, then once the user enters...
Create two java programs. The first will ask the user to enter three integers. Once the three integers are entered, ask the user to enter one of three functions. The “average” if they want the average of the three numbers entered, enter “min” if they want the minimum and “max” if they want the maximum. Display the answer. Ask the user if they want to calculate another function for the three numbers. If so, loop and ask what function they...
c++ QUESTION 9 Write a code that ask the user for the number n of decimal to average. Then n times the code the user to enter all numbers that you save or accumulate each time. Finaly print to the console the average of the n values the user entered using the format: cout << " The average of the " << n << " number you entered is: " << averagedValue <<endl;
Python code Write a program that will ask the user to input two strings, assign the strings to variables m and n If the first or second string is less than 10 characters, the program must output a warning message that the string is too short The program must join the strings m and n with the join function The output must be displayed. Please name the program and provide at least one code comment (10)
C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...
Rules to follow are:Declare an array with 1000 elements of type intThen in a loop generate 1000 random numbers and assign one to each element in the arrayThe random numbers should be between 1 and 50do not use rand or srand, use code is providedThen, prompt the user to enter a number, store this number in a local variable, the number should be safety checked using the GetInteger() functionThen, iterate through the array and determine how many times the user's...
This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...
MUST BE WRITTEN IN C++ All user input values will be entered by the user from prompts in the main program. YOU MAY NOT USE GLOBAL VARIABLES in place of sending and returning data to and from the functions. Create a main program to call these 3 functions (5) first function will be a void function it will called from main and will display your name and the assignment, declare constants and use them inside the function; no variables will...
Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file doesn’t exist. You will process through the file skipping any text or real (double) numbers. You will print the max, min, sum, count, and average of the integers in the file. You will want to create test files that contain integers, doubles, and Strings. HINT: Use hasNextInt() method and while loop. You may also want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of...
Function / File Read (USING MATLAB) A) create a user-defined function : [maxsample , maxvalue , numsamples]=writetofile(sname,strgth) to do the following: The user-defined function shall: -Accept as the input a provided string for the sample name (sname) and number for strength (strgth) - open a text file named mytensiledata.txt, with permission to read or append the file. - Make sure to capture any error in opening the file - Write sname and strgth to the file - Close the file...
Structures in C++ :- 1. Write a program that declares a structure to store the code number, salary and grade of an employee. The program defines two structure variables, inputs record of two employees and then displays the record of the employee with more salary. 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then...