C++ :: Pass Array Of Int And Its Size - Print Out Numbers Above Average
Nov 15, 2013
I am attempting to write a program " that has a function that is passed an array of int and its size, and with that it prints out only the numbers that are above average. "
I have included my code so far, but I am only getting one value as output, and that value seems to be completely off. I keep trying, but I am really stuck.
#include <iostream>
using namespace std;
int average(int values[],int size);
int main(){
int size;
int values[] = {1,2,3,4,5,6};
[Code] ....
Added the floats in the average() function. But there is still a value problem.
I must write a function that has a one dimensional double array and the number of values in the array as its arguments. Normalize the values. I must also print the maximum, minimum, average and numbers of values above the average in the array.
The equation that computes the normalized value from a value x is:
My code does not print the correct normalized value, average and values above average.
Code: #include <stdio.h> int findMax( double array1[], int num_elements) // This function computes the maximum value of the array { int i, max=-32000; for (i=0; i<num_elements; i++)
I was trying to make a program that asks the number of grades, get the grades and then get the average. I know I have to save the grades in an array but i don't know exactly how.
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;
array is a one-dimensional array of integers and n is the number of elements in that array that contain valid data values. Both of these are input parameters to the function. The function must calculate 1) the average of the n integers in array, storing the result in ave; 2) the average of the positive numbers (> 0), storing the result in avePos, and 3) the average of the negative numbers (< 0), storing the result in aveNeg.
void avgs (std::vector &array, int &ave, int &avePos, int &aveNeg) { int sum = 0, pos_sum = 0, neg_sum = 0, pos_count = 0, neg_count = 0; for (auto i : array) { sum += i; if (i > 0) { pos_sum += i; ++pos_count; }
I am facing a problem which i could not obtain the total numbers which is greater than the average value. For example:
#include <iostream> using namespace std; int main (){ int size , count; double no, max, min ,total, sum , average;
[Code] ....
In this case im able to compute the average of the numbers but when it comes to capture the total of numbers which is greater than the average value, how to compile the code , because the average number is only been compute once all the value capture by the input of user is sum up.
I am having trouble getting the stars to output correctly in the printStars function. the final output should look something like this:
#include <iostream> using namespace std; int readArray(int input[], int size); void printArray(int input[], int count); void printStars(int input[], int size);
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];
comparing with screen size the height is bigger but lenght is smaller. I don't understand.
I can understand that different printers process the fonts in different way and then to have different lenghts. That's not the problem. The problem is I need to simulate in screen the same behaviour i will have on printer because these texts are being aligned in the document, and I don't want to see that the text si aligned different in text than in paper.
What can I do to render the text on screen with the same size I will have on the printer? Print preview is doing it. Should I change the font parameters? is something related with pixels per inch?
My C programming class wants us to write a program to read integers into an array, sort the numbers and print out the occurrence of each number. I've tried everything that I can think of but the core dump is still occurring.
void countValues ( FILE *inf, int list[], int size ); /* Function prototypes. */ void printFrequencies( const int list[], int size ); int main (void) { int status = EXIT_SUCCESS; /* defaulting status to success. */ FILE *inf = fopen( "numbers.txt", "r" ); /* input data file */
#include <stdio.h> float total, avg, max, min; float judge[4]; int index; int array[4]; int main() { total = 0.0; max = array[0]; min = array[0];
[Code] ....
I dont understand how to make the array when it prints out only print out the final average and the final maximum score with the final minimum score but what its doing at the moment is just giving an average for each individual score taken...
Minimum and maximum scores are displaying 0.0
And it displays these things 4 times in a row i just want it to be displayed once.
I am trying use a print function to print out data in a struct. My questions are:
1. I have to use pass by reference. For the print function, I am passing the struct pointer as a reference, however, I don't want the print function to accidentally change anything. How can I make it use const to ensure that?
2. The deleteprt function doesn't look right to me. I feel like it should just be delete ptr not delete [] ptr.
I have loaded and 1d array from a .dat file, calculated the average of all the numbers. Now I need to count every number in the array that is below the average and cout that number. This is the method in the class I have so far:
I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort
Code:
void Sort(int ary[], int size) { int temp; int smallest; int current; int move; }
[code]....
put it wont print the numbers sorted when I use my print function, just the unsorted numbers.
I have the random values down but when I try to assign randValue to another integer I get an error.I want to make an inner loop where I find 5 random number 50 times and print the average of those numbers.
I know I have the bare bones of the below, but without giving me a huge shove in the right direction can I have a poke? I have been programing for three months now. I have noticed when I do simple fun projects I learn more then what my professor assigned to me. The class is over but I want to keep building.C++ starts in one week...
I need to implement a C++ program that asks the user for four floating-point numbers. The program should then calculate the average using two different functions, one value returning and one void. The program should output the average of the four numbers. For this program I need to use float instead of int for the types of variables. Below is a proto-type code that I am able to use to do this program.
#include <iostream> using namespace std; int sum(int,int);
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 made a program that is suppose to receive 20 numbers or less and find the average, then show all numbers entered but my average does not show. It shows as 0 and a line pops up after every number returned. I am stuck and dont know how to fix the logical errors.
#include <iostream> #include <cmath> using namespace std; int main() { float num[20]; int amount_num;