C++ ::  How To Obtain Total Of Numbers Greater Than Average Without Using Array

Jul 27, 2014

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.

View 19 Replies


ADVERTISEMENT

C++ :: Find And Print Average Of Odd Numbers Greater Than 5 And Less Than 100

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

C++ :: Average Negative / Positive Numbers And Total Average?

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

C++ :: Getting Number Greater Than Average?

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

C/C++ :: Selectively Choose Only Numbers Greater Than 1000 In Array?

Aug 4, 2013

I am doing my assignment that will calculate total tax amount per day and per week and finally sum those up.

One of the requirement is to filter out any number in the array that is less than 1000 to be assigned a value of zero instead of the stored value so as not to add it in the calculation. How to fulfill this requirement.

View 2 Replies View Related

C++ :: User Input 10 Integers Of Array - Add Numbers Greater Or Equal To 10

Oct 29, 2013

create a program that asks the user to input 10 integers of an array the program will add the numbers greater or equal to 10.

View 6 Replies View Related

C :: Average And Total Of Six Integers

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

C++ :: Total Amount Of Even Numbers In Array - Expected Primary Expression Before Int

May 30, 2014

Trying to write a function, Even, that will tell you the total amount of even numbers in the array

#include <iostream>
using namespace std;
const int MAX_ROWS = 3;
const int MAX_COLUMNS = 2;

int Even(int A[int length][int width], int length, int width) {

[Code] ....

View 1 Replies View Related

C/C++ :: Get Average Of Numbers In Array

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

C++ :: Calculate Average From File Containing Array Of Numbers?

Feb 21, 2014

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;

[Code] .....

View 7 Replies View Related

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.

View 1 Replies View Related

C/C++ :: Find Average Of 10 Numbers Passed To Array Using Function?

Jun 20, 2012

find the average of 10 numbers to an array using function .the array should be controlled by while loop?

#include <iostream.h>
float sum(float x[],int size);
    main() {
   float a[10];
int n=10;

[Code] .....

View 2 Replies View Related

C :: Array Add Total Rows And Total Columns

Apr 16, 2013

Code: i am trying to display the information in the array as a table and add the total rows and the total colums separately

#include<stdio.h>
int main(void)
{
int row, col;

[Code].....

View 1 Replies View Related

C++ :: Write A Source Code That Find Smallest / Largest And Average Of Numbers From Array

May 13, 2014

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];

[Code]...

View 5 Replies View Related

C++ :: How To Obtain Length Of Array That Has Been Sent Throughout Function

Sep 9, 2013

How can I obtain the length of an array that has been sent throughout a function. In the following code, I obtain "2" as output, while I was expecting "5".

void call(int a[]) {
cout<<sizeof(a)/sizeof(int);
}
int main() {
int* a=new int[5];
call(a);
}

How can I properly call this function so I can obtain the correct array size?

View 2 Replies View Related

C++ :: Elements Greater Than The Array Max?

Dec 11, 2013

im trying to write a program that finds the max in an array and divedes it by two than oututs a modfied list with all the elements greater than the max/2.

I got the first part but just not sure how to find the elements greater than the max/2 and output them correctly into the modfied list.

#include <iostream>
#include <iomanip>
using namespace std;

[Code].....

View 2 Replies View Related

C++ :: How To Count Total Integer And Floating Point Numbers In Text File

Feb 16, 2013

I have a text file like below read.txt:

1.0 2.0 3.0 4.0
2.0 3.0 4.0 6
5.0 7 1.0 5.0

calc.cpp:

void main() {
FILE *fp;
fp=fopen("read.txt","r");
double *read_feature = new double*[3];

[Code] ....

I want to count all the numbers in my text file (read.txt). Read text file consist of floating and integer number. Answer for the above file would be integer=2 and float =10.

View 3 Replies View Related

C++ :: Count The Numbers Below The Average

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

C :: Find Average Of Random Numbers

Aug 17, 2013

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...

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUMBERS 5

int main(int argc, const char * argv[]) {
float randValue = 0.0;
int i;

[code]....

View 9 Replies View Related

C++ :: Average Of 4 Floating-point Numbers?

Mar 17, 2013

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);

[Code].....

View 3 Replies View Related

C/C++ :: Calculate Sum And Average Of A Sequence Of Numbers

Feb 17, 2014

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;

[Code] ....

View 8 Replies View Related

C/C++ :: Receive 20 Numbers Or Less And Find Average?

Apr 27, 2015

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;

[Code] ....

View 3 Replies View Related

C :: Flowchart - Program To Compute Average Of N Numbers

Feb 20, 2015

How can you draw a flow chart that will be used to write a program to compute Average of n numbers?

View 1 Replies View Related

C++ :: Read Three Numbers From Keyboard And Find The Average

Jan 17, 2013

1): write program to c++ to read three numbers from keyboard and find the average of the three numbers?

2): write program c++ to read two numbers from keyboard and swap between numbers like x=4; y=6; the result x=6; y=4;?

I think that int can do that job. but im not sure.

3): must be the result of positive example: (x+(-y)=z)?

with abs ?

4): values for each of : X= ;y= ;z= ;

View 7 Replies View Related

C++ :: Program To Calculate Average Of 3 Numbers - Undeclared Identifier

Sep 22, 2013

Write a program that will calculate average of 3 numbers

#include <iostream>
int
main(){
// prototypes:
float add_and_div(float, float,
float);

[Code] .....

i get the following errors:

error C2065: 'cout' : undeclared identifier
error C2065: 'cin' : undeclared identifier
error C2065: 'cout' : undeclared identifier
error C2065: 'endl' : undeclared identifier

View 2 Replies View Related

C++ :: Compute Average Median And Mode For Numbers In Vector?

Feb 23, 2014

I needed to compute average median and mode for numbers in a vector. Im having a few issues I have already figured out how to calculate average and median just not mode. Also the program crashes when 0 is entered instead of exiting nicely. Also i keep getting a error on line 47 saying primary expression expected before else.

#include <iostream>
#include <conio.h>
#include <math.h>

[Code]....

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved