C :: How To Calculate Sum Of Two Lines In Array (for Loop)

Mar 19, 2013

I'm having trouble figuring out how to calculate the sum of two lines in the array(for loop)? And the next part, I can return the values to the main program however, how do I do it with c pointers?

(1) Write a C function that takes an integer array argument. The array argument has two rows and NDATA columns where NDATA is a symbolic constant. For each column in the array argument, the function calculates the sum of the values in the first and second row. The function returns to its calling program (using a second argument and call by reference as implemented with C pointers) the maximum of these sums. Additionally the function returns the column subscript where this maximum first occurs. This subscript value is returned the usual way (using a return statement). etc...

Here is the start of the array program

Code:
#include<stdio.h>
#include<stdlib.h>
#define NDATA 5 /* define number of data per row */
int row; /* count rows */
int column; /* count columns */

[Code] ....

View 2 Replies


ADVERTISEMENT

C++ :: Using A For Loop To Input And Output Array Values Also Calculate The Average

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

C++ :: Creating A Loop To Calculate Formula?

Mar 21, 2014

I am trying to create a code and cannot get the following part to work :

for (int n = 0; n = timesteps; n++)
{
n = n + 0.1 ;
cout<< "timesteps"<< n << endl ; //print time step value =0.1
for (int j = 0; j < nodesinx; j++)
{
T[j][n+1] = T[j][n] + 0.16 * (T[j][n] - 1[n] - 2[T[j][n] + T[j] + 1[n] ; //equation
n= n + 0.1 ;
cout<< "temperature" << T[j][n+1] << endl;
T[j][n+1] = 0.0 ;
}
}

View 1 Replies View Related

C :: Program To Calculate Factorial Of Numbers - For Loop

Feb 5, 2013

I have been working on a program to calculate the factorial of numbers. Part of my code is copied and modified from the FAQ about validating numbers in user input.

I have encountered a problem with the for loop that I am using near the end of my code. No matter what I do, it seems that my loop only does the multiplication of b = a*(a-1) and then prints. For example, inputting 5 will result in a print of 20, but the factorial is 120.

Code:
int main(void) {
char buf[BUFSIZ];
char *p;
long int a;
long int b;
long int i;

printf ("Enter a number to be factorialized: ");

[Code] ....

View 5 Replies View Related

C++ :: Calculate Handicap For Each Score Input - Do While Loop

Apr 28, 2014

I need starting a do-while loop in my program that runs up to 10 time that asks the user to enter up to 10 scores, which include the slope and rating for the course, and calculates the handicap for each score. Here's what I have so far:

//This program calculates a golfers handicap.
#include <iostream>
#include <string>
using namespace std;
int main(){
int score, slope;
double rating, handicap;

[Code] ....

View 4 Replies View Related

C++ :: Calculate Wages For Employees - Loop Closes Before Finishing

Dec 11, 2013

I'm writing a code that's suppose to do a payroll for my intro cs class. At first it was working fine until I had to add the part that made sure a user couldn't enter a wage value below $6.00 and now it stops the loop right after that part for some reason.

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int const HR = 7;

[Code] ....

View 2 Replies View Related

Visual C++ :: Program That Take Input From A User And Calculate It In A Do While Loop

May 15, 2013

I'm trying to create a program that will take input from a user and calculate it in a do-while loop. The program does the calculation but the answer is wrong. The loop also doesn't work. The purpose of the program is to see how much an item will cost after a discount is taken off and tax is added.

#include <iostream>
#include <cmath>
using namespace std;
double original_cost;
double discount;
double tax;
double total;
char answer;

[Code]...

View 2 Replies View Related

C++ :: Calculate Average Of A Stream Of Positive Numbers - Loop Program?

Feb 25, 2013

Write a program that calculates the average of a stream of positive numbers. The user can enter as many positive numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, treat zero as a positive number, i.e., zero counts as a number that goes into the average. Of course, the negative number should not be part of the average. You must use a function to read in the numbers, keep track of the running sum and count, compute the average, and return the average to the main() function. Note that you must use a loop to do this, as you don't know how many numbers the user will enter ahead of time. I am having problem writing a loop program for it..

View 1 Replies View Related

C++ :: How To Store Multiple Lines In Array

Oct 13, 2013

int statarray[] = {61, 66, 47, 50, 372,
62, 66, 47, 50, 372, 50, 54, 64, 45, 331, 49, 52, 58 69, 356,
58, 80, 50, 48, 389, 76, 64, 60, 59, 401, 76, 59, 57, 54, 422,
53, 45, 45, 52, 253};

I'm getting a bunch of different errors with this, how do we do this?

View 2 Replies View Related

C++ :: Reading Lines From A File Into Array?

Sep 1, 2014

The first part of the exercise is to read the lines from a file placing each line into an array. I thought my code looked correct however nothing but garbage prints out. Here's my code.

#include <iostream>
#include <fstream>
#include <string>

[Code]...

View 2 Replies View Related

C :: Reading Lines From A File And Storing It In Array From Typdef Struct

May 4, 2013

I'm trying to read in lines for a file and storing it in an array. This is what I have so far. Am I allocating the memory correctly?

Code:

typedef struct {
/* declartion of variables */
} App
typedef struct {

[Code].....

How do I access the array content? I'm suppose to strtok the contents from the lines stored in the array and use it again.

View 2 Replies View Related

C++ :: Calculate Mean Of Array Class?

Jan 16, 2013

I am trying to create a small function that can return the mean of an object of array class, not a simple array.

Declare and initiate the array:

array<double, 100> myArray = {};
myArray.fill(1.0);

function to calculate mean:

double mean_array(double *array)
{
double sum = 0.0;
for(int i=0; i<sizeof(array); i++)
sum += array[i];
return sum / sizeof(array);
}

However, it does not work. It seems it is incompatible with the array definition.

View 8 Replies View Related

C/C++ :: Calculate Offset Of 3dD Array?

Apr 1, 2014

Is this the correct way to calculate the offset of a 3d array? Also is the dynamic allocation for it in the main program correct?

Some how it's not working fine after I input the values for some values of x,y,z e.g when the const ints are 2.

#include <iostream>
using namespace std;
const int x = 2;
const int y = 2;

[Code]....

View 8 Replies View Related

C++ :: Calculate Average From Array Values

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

C :: How To Calculate Largest / Smallest / Average - No Array

Feb 16, 2015

i'm having trouble trying to make this code works .. the program must repeatedly asks user for the age of a person until user enters -1 ,, once he/she entered -1 the program calculates ( smallest value entered, largest value , and average )excluding -1 from calculation

i've been working on this for a weeks this is the best i could do.i know average must add all the entered values , not only smallest and largest but how can i do that here ?

Code:

#include<stdio.h>
int main(void)
{
int age ;
int v;
int counter;
int l=0;
int s=0;
int limit;
}

[code]....

View 13 Replies View Related

C++ :: Calculate Mode / Mean And Median Of Array Of Integers

Mar 17, 2013

I'm writing a program that calculates the mode, mean and median of an array of integers. I've done the mean and median but i can't figure out mode.

I have to find the number of modes.

Ex array of integers: 10, 10, 4, 5, 6,5, 6, 7

My function has to return the number 3. Because there are 3 sets of mode; 10,5,6.

How do i implement this in my function because for now it just calculates the mode. It only return the number mode 10.

View 5 Replies View Related

C++ :: Calculate Average Of Array And Print Elements

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

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++ :: Using Loop To Process Array Of Characters Starting From Beginning Of Array?

May 3, 2014

Assume you want to use a loop to process an array of characters starting from the beginning of the array. You want the loop to stop when you read the null terminator character from the array. Fill in the loop test condition that will make this work correctly.

index = 0;
ch = array[index];
while ( _____________________________)
{
// process the character
index++;
ch = array[index];
}

View 1 Replies View Related

C :: Calculate Number Of Distinct Values Entered Into Array

Sep 12, 2013

I'm trying to calculate the number of distinct values entered into an array. If i enter the followings "3,4,5,6,7,7,6,e (anything that's not a number)" . I get a total of 7 but in reality it should be a 5.

Code:

#include <stdio.h>
//---------function to find the distinct values----
int find_distinct(int list[], int size)
{
int i, j,size2, distinct = 0;
for(i = 0; i < size; i++)

[Code]...

View 9 Replies View Related

C/C++ :: Calculate Percentage Of Even Numbers Entered By User In Array

Nov 18, 2014

exercise in c: write a program which calculates % of even numbers entered by a user in an array;

1) check if user hasn't entered float value; if has issue warning;
2) give the option for user to press "stop" to exit program any time.

int c,sk[100],i,sum1=0, sum2=0, rel;
printf ("How many numbers will you enter?
");
scanf ("%d", &c);
printf ("Enter %d numbers (to exit program press - stop)
", c);

[Code] ....

View 1 Replies View Related

C++ :: Two Dimensional Array - Calculate Final Scores Per Diver Who Each Get Five Dives

Jan 31, 2014

I have to create a program that calculates the final scores per diver, who each get five dives. I have to include the difficulty level when figuring out this score, and I need to drop the highest and lowest scores.

Now, I'm reading from a file where the values are something like:

234 :Diver number
2.3 :Difficulty
2.1 3.2 4.0 2.3 3.8 :Scores

Would I create a parallel array for the difficulty, or include it in a 2D array with the scores. Something like

score[Difficulty][individualScores]; ?

Also, would I include a findMin and findMax in a function that calculates the total, seeing as how the highest and lowest must be dropped to determine the final score?

View 11 Replies View Related

C++ :: Using Array Of 5 Scores And Calculate Average / Highest And Lowest Score

Apr 11, 2013

it compiles and runs, it gives me the average and the highest score but says lowest is 0 even though 0 is never entered.

Write a program which uses an array of 5 scores and calculates the average score, the highest score and the lowest score.

#include <iostream>
using namespace std;

int getHighest(int [], int);
int getSmallest(int [], int);
double getAverage(int [], int);
int count;
int numbers;

[Code] ......

View 2 Replies View Related

C++ :: Store User Input In Array And Calculate Mean / Median And Mode - Bubble Sorting

Mar 26, 2014

I'm trying to make a c++ program of this but i don't know how to use the bubble sorting.

Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.

Mean is the average of the 10 numbers.
Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.)
Mode is the most frequent number among the 10 numbers.

View 5 Replies View Related

C/C++ :: Array With Two Variables And Loop

Feb 18, 2014

I have two variables t and x in an array that alternate. I want to add two t's and find the average and then do the same for the x's. After that, I want to find the slope of x -> t. My problem is that I specify the n for t, but since it's local I can;t use it for the slope. Here's my code so far:

#include <iostream>
using namespace std;
int main() {
double PA [8] = {0.0001234, 1.0005434, 0.0005678, 1.0023423, 0.00063452, 1.0001546, 0.00074321, 1.00017654};

[Code] ....

And, can I actually use the n2 as an index, or will the processor not understand that?

View 7 Replies View Related

C++ :: Array Container For Loop?

May 13, 2014

I want to find all instances of a substring mysub in array container myarr and replace each occurrence of mysub with empty string " ". To do that, I'd like to use for loop with search algorithm.

Code below:

p=array iterator
for ( p=search(myarr.cbegin(),myarr.end(), mysub.begin(),mysub.end();
p!=myarr.end();
p=search(p,myarr.end(),mysub.begin(),mysub.end() ); {

[Code] ......

View 2 Replies View Related







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