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
ADVERTISEMENT
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
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
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
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
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
Feb 20, 2013
I have to write a c++ program with my own function which consists of two parameters (day, month). Function have to return number of days since the begining of this year. Using this function i have to find out how many days are left till birthday (or how many days have passed since last birthday)
This is how far i am:
Code:
#include <iostream>
using namespace std;
int cikDienu(int diena, int menesis);
int main()
[Code] ....
View 9 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 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
Mar 22, 2013
I am posting this simplified piece of code that is a bit confusing for me. There are two functions that I call. One shows the expected results but the result of the other one rather puzzles me.
//#define defineVecTyp Vec3f
#define defineVecTyp float
template <typename vecTyp>
vecTyp buildLaplacianPyramid(cv::Mat inputmat) {
vecTyp lapPyr;
[Code].....
Calling the function sum1 does not change the values stored in the variables val1 and val2. The output of the program is as follows:
val1= 1 ## val2= 10 // before the call of function sum1
val1= 1 ## val2= 10 // after the call of function sum1
sumOfVals= 22
This is quite obvious and as expected and I just pasted this piece of code as an example for better clarification.
However, if I call the function buildLaplacianPyramid and apply a function for Gaussian Blurring, this also effects the cv::Mat passed to the function. The line imshow("M1, after buildLaplacianPyramid",M1); therefore shows an image that is blurred. Since I am not passing a pointer to the cv::Mat I do not understand why this should be happening. I was assuming that there would be a copy of the cv::Mat M1 to be used within the function. Therefore I was expecting the cv::Mat M1 to retain its original value. I was expecting that all changes applied to cv::Mat inputmat within the function would not have any influence on the cv::Mat M1. Just like in my other example with the sum.
View 3 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
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
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
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
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
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
Dec 7, 2013
Question: How to find a duplicate numbers and numbers found once in array.
View 7 Replies
View Related
Nov 29, 2014
How to power value in function too.
View 2 Replies
View Related
Dec 4, 2014
I missed last class on doing void functions because I got sick and im completely lost! ive being using the texts book example for a reference but its not running !
The output should look similar to this:
how much was your shirt?
20
shirt 20.00
tax =1.20
the total 21.20
Code:
include <iostream>
#include <iomanip>
using namespace std;
void getShirtCost(double shirtCost);
void calculate(double shirtCost,double taxAmount, double total, double taxamount) ;
void printReceipt(double shirtCost, double taxAmount, double total, double taxamount);
[Code] ....
View 1 Replies
View Related
Aug 25, 2013
I wrote this GCD function to find gcd of an array of numbers . Here is the code:
long long GCD(long long min,int loc,long long b[]) {
for (long long i=min;i>0;i--) {
bool p=0;
for (long long x=0;x<loc;x++) {
if (b[x]%i!=0)
[Code] ....
Its returning wrong answers. When i tried 6 14 it returns 6
View 6 Replies
View Related
Aug 19, 2013
I wrote some code for class to find prime numbers.The teacher says that I need to revise my code with the requirement below: use a bit array to store the prime number checking. The bit array will also be in the heap. Use the max value of an unsigned 32-bt integer (UINT_MAX) to be the maximum size of the prime number you want to check.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <getopt.h>
#include <ctype.h>
#include <stdint.h>
//function to set all non-primes to 0
void *zero_multiples(void *threadid);
[Code] .....
View 4 Replies
View Related
Jul 17, 2012
When I run my program it just gives me 'The smallest number is: 2682760' which isn't true obviously.
Code:
#include <iostream>
int main() {
using namespace std;
int x, smallest;
int Array[7] = {7, 5, 10, 13, 3, 15, 54};
x = Array[0];
[Code] .....
View 3 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
Mar 20, 2014
What shall I learn in order to send values from 0.00 to 5.00? I'm working with they Hitachi 16x2 LCD display.I've been sending/displaying literal values on it all day.
Code:
SendCharater(unsigned char val)
where the variable val corresponds to the LCD character table.I can also send Hello World to the display, like so:
Code:
void putsXLCD(unsigned char *buffer){
while(*buffer) // Write data to LCD up to null
{
while( BusyXLCD() ); // Wait while LCD is busy
SendCharacter(*buffer); // Write character to LCD
buffer++; // Increment buffer
}
return;
}
I could type in putsXLCD("5.00") in order to display it on the LCD, but how do I implement this automatically for values, e.g. 0.00 to 5.00?It appears I can only pass literal values through the function SendCharacter, meaning that in order to display "0" I have to pass the value 0x30 (the hex value of "0" on the LCD Table).
My current thought process:Much like passing "Hello World" in the function putsXLCD(), I need to assign a pointer that points at each value in the "array" that I need to send. E.g., I need to send 3.24, so I need to point to "3", fetch the corresponding hex value in the LCD table, in this case 0x34, and the pass this 0x34 into the SendCharacter function, and so on. So, if this is the case, how can I fetch the corresponding hex value?
View 7 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
Oct 24, 2014
I need to find the smallest number in my 10x8 arraygrid with random numebr filled in it
Here my Code:
#include <iostream>
using namespace std;
int main() {
int total,average,smallest;
int row=0;
int col=0;
[Code] ....
View 2 Replies
View Related