C :: How To Calculate Largest / Smallest / Average - No Array
Feb 16, 2015
i'm having trouble trying to make this code works .. the program must repeatedly asks user for the age of a person until user enters -1 ,, once he/she entered -1 the program calculates ( smallest value entered, largest value , and average )excluding -1 from calculation
i've been working on this for a weeks this is the best i could do.i know average must add all the entered values , not only smallest and largest but how can i do that here ?
Code:
#include<stdio.h>
int main(void)
{
int age ;
int v;
int counter;
int l=0;
int s=0;
int limit;
}
im trying to write a source code that find the smallest, largest and average of numbers in array. the code runs fine, but it is not giving the highest number and the the average should include only four number excluding highest and smallest number from the array.
void OlympicJudging() // Olympic Judging { int numbers [6]; double average, sum = 0; int temp; for(int i = 0; i < 6; i++){ cout << "Please type a value for scores: "; cin >> numbers[i];
I'm trying to write a program that will allow a user to enter infinite numbers (one at a time) with a way to stop entering values, and once it stops it immediately displays:
Lowest number: Highest number: Number of values entered: Average of numbers:
what I can't figure out is:
-how to end the loop with something other than a number, preferably a char, so that it doesn't affect the average/lowest/highest
-how to output the lowest and highest numbers in a loop (would be easier to figure out were it finite and I could just type a bunch of printf/scanf)
What I have so far:
Code:
#include <stdio.h>#include <stdlib.h> #define pause system("pause") main(){ //n = amount of numbers input //x = number given by user //s = smallest number //l = largest number }
I seem to have reached a dead end in a program I am attempting to write.The purpose of the program is find the smallest, largest, and average values in a collection of N numbers. It needs to get the value of N before scanning each value in the collection of N numbers.I'm having trouble creating comparisons for each set. I have a feeling because of the way I structured my program, I'm unable to make a proper comparison. Maybe my approach was wrong as soon as I got to the for statement to loop N sets and N numbers.Here is my code so far:
Code:
#include <stdio.h> int main (void) { int num_sets, num_of_integers; int count, count2, set, sum = 0; int num, avg; }
[code]....
/* Here is where I would continue to attempt to make a comparison between sets to determine smallest to largest */
Write a program that reads in a list of integers into an array with base type of int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be a two-column list. The first column is a list of the distinct array elements; the second column is the count of the number of occurrences of each element. The list should be sorted on entries in the first column, largest to smallest.
For example, for the input -12 3 -12 4 1 1 -12 1 -1 1 2 3 4 2 3 -12
the output should be N Count 4 2 3 3 2 2 1 4 -1 1 -12 4
Here's My code So far:
#include <iostream> #include <fstream> using namespace std; const int SIZE = 50;
[Code]....
My Code outputs the numbers From Largest to Smallest according to given array, but I need to make it to output the numbers once(if its repeated)
I am working on a c++ assignment and I need to display the smallest and largest values of an array called from a .txt file...but I don't know how to display them...
Write a program that uses two functions; one finds the largest number and second largest number; and second function finds the average. The data, comprising of 20 different temperature values, is available on a file.
And here is my output when I run the program. 75 Max: 90 Min: 0
Press any key to continue . . I am reading from a file in this program which contains a set of 30 numbers and it has the average correct and the max correct but the minimum number in the set is 56 however it keeps giving me a zero for the min.
The only part I have working is getting all odd random numbers but the logic in getting the largest and smallest from random is what is giving me alot of trouble.
class Program { static void Main(string[] args){ int num = 0; int largest = 0; Random rand = new Random(); for (int ctr = 1; ctr <= 100; ctr++)
[code]....
Console.Write("{0,5} The larget number out of 100 odd numbers is: {1:n}",y,largest);
How to find the largest and smallest number entered by a user. So far I'm able to add, find the average and count how many numbers are entered.
I'm just having trouble with find the max and min. I tried if statements and it breaks the program will it wont let me exit the while loop or the program will do a force close after entering a value.
Code:
#include <stdio.h> #include <stdlib.h> int main(){
int maxNum=0, minNum=0, value, count=0, sum=0; double average;
I am trying to Write a program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers. How do i go about it. What i dont know is how to come up with smallest and largest number .
I'm suppose to write a program using (for loop) that asks the user to enter any amount of numbers, so that it can display the smallest and largest. My program successfully finds the largest, but it is always displaying 0 for the smallest, I think Im doing something wrong with the internalization but I dont know what to change it to.
This is what I have ....
#include <iostream> using namespace std; int main() { int amount; int count; int number = 0; int smallest = 0; int largest = 0; cout << "Enter total numbers to process: ";
i wrote following code to calculate average of the values entered to the array.After displaying the output following error was displayed.
"Run-Time Check Failure #2 - Stack around the variable 'marks' was corrupted.
A buffer overrun has occurred in q 3 410005111.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program. "
//Average mark of student 1 cout<<"Avarage mark of the student 1 :"<<(marks[0][0]+marks[1][0]+marks[2][0]+marks[3][0]); cout<<endl;
I have written two separate programs; Program 1 calculates the average of an array of numbers which has been hard-coded into the program. Program 2 reads an array of numbers from a text file and displays them on the output.
I wish to combine these two programs into one by making Program 1 read the array of numbers from the file and then calculate the average using that instead of the array { 84, 92, 76, 81, 56 } as outlined below. I only wish to display the average in the output, not the number array as Program 2 does.
I have tried to do most of the work, I just need modifying the code slightly so it reads the number array from the file and calculates the average.
Program 1
#include <iostream> #include <cmath> #include <math.h> #include <fstream> #include <string> #include <numeric> using namespace std; int main() { const int nNumStudents = 5;
I have this code that im stuck on what i need to do is Extend the code such that when it starts the user is asked to input values to specify each of the three ranges before moving on to accept and tally the main values how do i do that Using a for loop to input and output array values Also calculate the average
*/ #include <stdio.h> int main(void) { /* Declare an array of integers */ int Grades[5]; int nCount; int nTotal = 0; /* Declare and initialise the value */ float fAverage;
Write a C program that calculates the sum and average of a sequence of numbers. Assume the first number specifies the number of values remaining to be entered. If the first number is less than 1, then the program should display an "Invalid Entry ... Please enter a positive number." message.
THIS IS HOW IT SHOULD COME OUT... Enter the number of values to process 0
Invalid Entry ... Please enter a positive number.
Enter the number of values to process 3 Enter 3 numbers: 1 2 3
Sum: 6 Avg: 2
THIS IS THE CODE I HAVE SO FAR...
#include <stdio.h> int main(void) { int total=0; int howmany; int i; int value;
I need to create a program that has has an array size of 20 and will generate 20 random numbers in it between 1-1000. Then I need to calculate the average of all the random numbers.
I have half of the code done ,but im lost on how to calculate the average of the random numbers.
Here what I have:
#include <iostream> using namespace std; int i; int size[20]; int counter = 0; int main() { cout << "The Array Consists Of 20 Random Numbers: "<<endl<<endl;