C :: Print Correct Normalized Value / Average And Values Above Average
Nov 14, 2013
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:
Normalized x= (x-min(array))/(max(array)-min(array))
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++)
[Code] .....
View 5 Replies
ADVERTISEMENT
Apr 9, 2014
write a c++ program that reads an unknown number of integer values and then print count, sum and average of odd values, even values, positive values, negative values!!
View 1 Replies
View Related
Nov 18, 2013
I am trying to average the negative numbers and positive number and of course the total average.
This will read in a list of n values, where n is not known ahead of time. The number of values read into the array will be saved in n.
vector<int> readList() {
std::vector<int> result;
ifstream inFile;
inFile.open("setA.txt");
for (int x; inFile >> x; ) {
result.push_back(x);
[code]....
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; }
[code]....
View 1 Replies
View Related
May 21, 2013
Howe can i display the average of 100 values in c++ 2008....
View 4 Replies
View Related
Nov 5, 2014
I am new to programming in C++, and have got a project on this.
Write a C++ program that accepts three numbers from the user (All are integers):
Such as:
Enter the first mark: 3
Enter the second mark: 25
Enter the third mark: 23
The program should find and print the average of the odd numbers greater than 5 and less than 100.
View 4 Replies
View Related
Oct 23, 2013
Use function decomposition.
-To prompt user to enter value and assign it to correct position in array
-calculate the average of an array
-display all element.
-display average.
For some reason, i keep getting error and it doesn't compile. I use Dev-C++
Here is my code:
#include <iostream>
#include <iosmanip>
#include <math.h>
using namespace std;
const int SIZE = 5;
const int LINE = 4;
//function prototypes
void getData(int arr[]);
[Code]...
My error is on line 69. I don't see anything wrong with it.
If i take out setw(3), it doesnt get any error but for some reason it doesnt run. Possible i did something wrong there?
View 2 Replies
View Related
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.
View 1 Replies
View Related
Jan 8, 2014
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;
View 5 Replies
View Related
Aug 14, 2014
how to compute the averages for 6 values that have been computed from a for loop,
I mean once the for loop finishes it prints me six different values classified into 3 groups as shown down:
group1 has value1
groupe2 has value2, value3, value3
group3 has value5, value6
I want to find the average for each group.
considering the number of values in each group might change. this is the code for finding the values:
for (int i=0; i<n; i++)
{
if (value < 25)
{
[Code]....
View 5 Replies
View Related
May 30, 2014
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 */
return 0;
View 5 Replies
View Related
Jan 24, 2014
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;
[Code]...
View 1 Replies
View Related
Aug 27, 2014
#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.
View 1 Replies
View Related
Feb 6, 2015
#include <iostream>
using namespace std;
int num_ints;
int num_doubles;
double running_total;
double average;
[Code] .....
View 1 Replies
View Related
Mar 20, 2013
Cannot divide the real output of the AVERAGE.:
Code:
#include<stdio.h>
#include<conio.h>
struct student
{
char Name[50];
[Code]....
View 7 Replies
View Related
Nov 29, 2014
How to power value in function too.
View 2 Replies
View Related
Nov 10, 2013
I have to get the average score for each student. And modify my avgmarks function and write the marks to a output txt file.
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int bubble(int*,int);
void filewrite();
void avgmarks();
void fileprint();
void filesort();
void rollin();
[Code] .....
View 1 Replies
View Related
Jan 22, 2013
"Write a program that prompts the user for an integer number from the keyboard, and store it in a variable num. After each number is typed in, add num to a total.
Do this six times, each time adding num to a total. (Be sure to reuse the same variable named num for each of the six numbers entered.) When all six numbers have been entered from the keyboard, calculate an average. Display the total and average calculated. "
Here is what I have so far:
Code:
#include<stdio.h>
int main() {
int num, total1, total2, total3, total4, total5, total6, avg;
printf("Enter first number:");
scanf("%2d",&num);
[Code] .....
View 2 Replies
View Related
Apr 16, 2013
I am attempting to write a program that takes a number(picked by the user) of test scores in an array then calculates the average and outputs the number of passed and failed tests.
On a side note I am attempting to use array notation in the main function and pointer notation in the other functions
#include<iostream>
#include<iomanip>
using namespace std;
int numScores;
int counter = 0;
double *scores;
//Function Prototypes
[Code]...
View 3 Replies
View Related
Apr 12, 2013
I need to calculate the average and median of an array. I do not know how to put it in code.
View 1 Replies
View Related
Mar 7, 2013
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:
int IntegerArray::countBelowAverage(int numBelowAvg) {
avg=IntegerArray::getAvg();
for(int ct=0; ct<avg; ++ct) {
numBelowAvg=ct;
}
return numBelowAvg;
}
My output from this is always 0 and I know that there are numbers below the avg.
View 2 Replies
View Related
Jul 24, 2014
#include<iostream>
using namespace std;
int main(){
int k,num,sum=0,GreaterNO=0;
double average;
[Code] .....
above is my program, I have received an assignment which the lecturer request us to find a series of k numbers then
-display the average
-display the total of numbers greater than the average
our lecturer request us do in 2 version, one is by using array, one is without using array, I have facing the coding problem when doing the VERSION WITHOUT USING ANY ARRAY to get the display the total numbers greater than the average, is there possible to get it?? because there are only one variable keep on looping, but the average will only get after get all the user input....?
View 8 Replies
View Related
Sep 14, 2014
What i need it to do is ask the user for a number of cases. The user will input numbers and the program should add the inputs until zero or a negative number is entered and then out put the average of those inputs. The amount of cases is pretty much how many times an average will be done. so if the amount of cases is 4. and the inputs are 1,3,(1+3/2)0 then it should output 2. and that would be ONE case, next inputs are 5,6,4,0(5+6+4/3) the output is 5 and that is case two. etc.
Here is my code:
#include <iostream>
using namespace std;
double avgVal(int, int);
int main() {
int amountOfCases;
cin >> amountOfCases;
int* numbers = new int[amountOfCases];
int input=0;
[Code] ....
View 2 Replies
View Related
Sep 3, 2014
My program works fine in all areas but adding the average every loop. It gives me a weird -1.#IND as an output, and it's supposed to calculate the total mileage each time I enter new values per trip.
// Automobile Mileage.cpp : Defines the entry point for the console application.
//
//Programmer: Ryan Youngen
[Code].....
View 1 Replies
View Related
Jul 5, 2014
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.
View 12 Replies
View Related
Dec 9, 2014
I need to create average calculating program using do while loop.
t = 1 - sin(x) when x > 0;
t = 1 + x when x = 0;
t = a + sin(x) when x < 0;
primary information:
x changes from 1 to -1 by step h = -0.5, a = -2
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
int a = -2;
[Code] ....
How this program should look that's why this probably looks just like a mess.
View 2 Replies
View Related
Dec 10, 2014
Write a program to compute average grades for a course. The course records are in a single file and are organized according to the following format: Each line contains a student's first name, then one space, then the student's last name, then one space, then some number of quiz scores that, if they exist, are separated by one space. Each student will have zero to ten scores, and each score is an integer not greater than 100. Your program will read data from this file and write its output to a second file. The data in the output file will be nearly the same as the data in the input file except that you will print the names as last_name, first_name and there will be one additional number at the end of each line: the average of the student's ten quiz scores.
The output file must be formatted such that first and last names appear together in a left justified column that is 20 characters wide where the last name comes first, then a comma and a space and then the first name. Use your read string function to read each name separately and then put them together into a larger correctly formatted string before trying to output them. Each quiz score should be listed in a right justified column that is 4 characters wide, and the average should appear in its own right justified column that is 10 characters wide.
Note that if a student has fewer than 10 scores, the average is still the sum of the quiz scores divided by 10; these students are assumed to have missed one or more of the quizzes. The output file should contain a line (or lines) at the beginning of the file providing appropriate column headings.
This is how much I have so far:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
char* read_string(char* buffer, int max_size, FILE* fp);
int main(int argc, char *argv[]) {
FILE *fp_input, *fp_output;
[code]....
View 7 Replies
View Related