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


ADVERTISEMENT

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++ :: 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++ :: 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/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 :: Find Smallest / Largest And Average Values In A Collection Of N Numbers

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

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++ :: 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/C++ :: How To Find Average With For Loop

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

C/C++ :: How To Find Average Of Three Groups Of Values

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

C++ :: Find Average / Highest And Lowest Score?

Oct 9, 2014

Create a 1-D Array to hold a set of exam scores:

55 74 93 84 64 72 69 78 87 84 72 33 83 68 62 51 88 90

Write a program to do the following tasks:

1. Display scores in rows of four(4) scores.

2. Calculate average score and display.

3. Find Lowest score and display.

4. Find Highest score and display.

5. Find the deviation of each score, and display the score and its deviation.

6. Find the Standard Deviation and Display

7. How many scores are within One Standard Deviation

So I have the average down, but I am getting stuck at the part of displaying the highest and lowest score. Every time I run the program I get two giant negative numbers for both of them. I put all the scores into a .txt file and I just opened in through the program.

#include "TCHAR.h"
#include <iostream>
#include <fstream>
#include <iomanip>

[Code]....

View 1 Replies View Related

C++ :: Program That Prompts User For 10 Grades And Then Find Average

Feb 24, 2015

I need to write a program that prompts the user for 10 grades and then find the average. I have that part but I need to average to not include -1. How can I tell the program to not calculate -1 into the average.

#include <iostream>
using namespace std;
int main() {
//Declare variables
float grade[10]; // 10 array slots
int count;
float total = 0;
double average;

[code].....

View 1 Replies View Related

C++ :: Dynamic Structures - Find Average Value Of All Elements In Deque

Dec 17, 2013

I have a question. How to find the average value of all the elements in a deque?

View 2 Replies View Related

C++ :: Find Average Of 5 Grades - Lowest Number Dropped

Nov 8, 2014

This is a simple program I am building to find the average of 5 grades where the lowest grade is dropped. I created a function findLowest() which accepts the 5 grades as arguments, finds the lowest grade and returns it as "lowest". I have tried many different way to find the lowest number. Right now, I am working with if...then statements.

#include <iostream>
using namespace std;
void printMessage(); //Prototype for printMessage
void getScore(int&); //Prototype for getScore with reference variable
int findLowest(int,int,int,int,int,int &); //Prototype for findLowest with reference variable

[Code] ....

View 2 Replies View Related

C/C++ :: Find Average Of 20 Students By Using A File And One Dimensional Array

Jan 22, 2015

is this according to it??

#include <iostream>
#include <fstream>
using namespace std;
int main(void){
fstream file("textfile.txt");
int linecount = 0;
int tempArray[100];

[Code] ....

View 1 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/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++ :: 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 :: 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++ :: 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++ ::  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 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

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++ :: Find Prime Numbers Between Given Pair Of Numbers And Store Them Into Array?

Apr 18, 2014

Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.

I'm stuck on how to put the prime numbers into an array.

The input file has the numbers 1 & 100.

Here's what I have so far.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin;
fin.open("numbers.txt");

[Code] .....

View 1 Replies View Related







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