i have a machine problem to do. it should compute for the average grade of N scholars. N will be entered on the keyboard and the Student No. and Grades of the Scholars in *8 Subjects will be entered.

sample output of program should be like this.
STUDENT NO. S1 S2 S3 S4 S5 S6 S7 S8 AVERAGE
113 80 80 80 80 80 80 80 80 80
144 90 90 90 90 90 90 90 90 90

i dont know if what im doing is correct. this program should be solve using arrays in c++.

help me! i really need this. please :(

here is the sample of the code i have done. i dont know if this is correct since i cant execute it because an error (shown below) is present.

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;


void Display(int ARR[], int SIZE, char C);
void Change(int ARR[], int SIZE);
int Increment(int x, int y);

int var_name[50];

int main()
{	
    int N;
    cout<<"Enter Number of Scholars: ";
    cin>>N;
    cout<<"\n"<<N<<" Scholars would be evaluated.\n\n";
    int j;
    int scholars[N];
    for(j=0;j<N;j++)
    {   int SN;
        cout<<"Enter Student Number for Scholar "<<j+1<<":";
        cin>>SN;
        int s;
        float GS;
        for(s=0;s<8;s++)
        {               cout<<"Enter Grade of Scholar "<<SN<<" in Subject "<<s+1<<":";
                        cin>>GS;
        }
        cout<<"\n";
    }
    cout<<"SN\tS1\tS2\tS3\tS4\tS5\tS6\tS7\tS8\tAVE\n";
    for(j=0;j<N;j++)
    {
    N=0;
    scholars[N];
    cout<<SN<<s+1<<s+2<<s+3<<s+4<<s+5<<s+6<<s+7<<s+8; //received an error in this area
    N++;
    }
    int p;
    cin>>p;
}

Recommended Answers

All 3 Replies

anyone please help!? a little help would suffice. please, i really need this.

im sorry if this may sound very basic but array programing was not taught to us.

i have a machine problem to do. it should compute for the average grade of N scholars. N will be entered on the keyboard and the Student No. and Grades of the Scholars in *8 Subjects will be entered.

sample output of program should be like this.
STUDENT NO. S1 S2 S3 S4 S5 S6 S7 S8 AVERAGE
113 80 80 80 80 80 80 80 80 80
144 90 90 90 90 90 90 90 90 90

i dont know if what im doing is correct. this program should be solve using arrays in c++.

help me! i really need this. please :(

here is the sample of the code i have done. i dont know if this is correct since i cant execute it because an error (shown below) is present.

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;


void Display(int ARR[], int SIZE, char C);
void Change(int ARR[], int SIZE);
int Increment(int x, int y);

int var_name[50];

int main()
{	
    int N;
    cout<<"Enter Number of Scholars: ";
    cin>>N;
    cout<<"\n"<<N<<" Scholars would be evaluated.\n\n";
    int j;
    int scholars[N];
    for(j=0;j<N;j++)
    {   int SN;
        cout<<"Enter Student Number for Scholar "<<j+1<<":";
        cin>>SN;
        int s;
        float GS;
        for(s=0;s<8;s++)
        {               cout<<"Enter Grade of Scholar "<<SN<<" in Subject "<<s+1<<":";
                        cin>>GS;
        }
        cout<<"\n";
    }
    cout<<"SN\tS1\tS2\tS3\tS4\tS5\tS6\tS7\tS8\tAVE\n";
    for(j=0;j<N;j++)
    {
    N=0;
    scholars[N];
    cout<<SN<<s+1<<s+2<<s+3<<s+4<<s+5<<s+6<<s+7<<s+8; //received an error in this area
    N++;
    }
    int p;
    cin>>p;
}

Line 22 - N is not known at compile time, so this won't work on most if not all compilers. You may get lucky and get it to compile, but this shouldn't be done. Visual C++ threw an error.

Line 39 - This line does nothing and is a segmentation fault, even if line 22 was correct.

Line 22 again - The scholars[] array is never used anywhere but in the non-sensical line 39. What is its purpose?

Line 35 - S1, S2, S3, what are these? Variables? They aren't defined anywhere.

Lines 38, 41 - Why are you changing N? Why are you not using j inside the loop?

Line 40 - SN is now out of scope since it was declared inside an earlier for-loop that has ended.

I think you need to put this assignment aside and go back to square 1 and take an array tutorial. Run the sample programs, try to get a feel for arrays and their syntax, then come back and try this program.

http://www.cplusplus.com/doc/tutorial/arrays.html

I would solve that as follows:

#include <stdio.h>
#include <stdlib.h>]
#include <conio.h>

void main()
{
  int **Registry;
  int nScholars;
  int i,j,sum=0;
  char *aux;
  do
  {
    printf("Enter the number of scholars: ");
    scanf("%d",&nScholars);
  }while( nScholars<0 || nScholars>100);
  Registry = (int**) malloc(sizeof(int*)*nScholars);
  if( Registry==NULL )
  {
    printf("Error!");
    getch();
    return;
  }
  randomize();
  for(i=0; i<nScholars;i++)
  {
    Registry[i] = (int *) malloc(sizeof(int)*10);
    Registry[i][0] = 100 + random(101);
    for(j=1; j<9; j++)
    {
      Registry[i][j] = 80 + random(21);
      sum = sum + Registry[i][j];
    }
    Registry[i][9] = sum/8;
    sum = 0;
  }
  printf("Scholar NO. S1  S2  S3  S4  S5  S6  S7  S8  Average\n");
  printf("---------------------------------------------------\n");
  for(i=0; i<nScholars; i++)
  {
    printf("%5d      %3d %3d %3d %3d %3d %3d %3d %3d %5d \n",
      Registry[i][0], Registry[i][1], Registry[i][2], Registry[i][3],
      Registry[i][4], Registry[i][5], Registry[i][6], Registry[i][7],
      Registry[i][8], Registry[i][9]);
  }
  free(Registry);
  getch();

}

I don't know how to use iostream, though it seems I should learn to because everyone here does.
Since the number of students is gonna be a variable, you need a pointer to a set of pointers, and each of those pointers point to an array of 10 integers. This way you can allocate in the heap as much memory as you're gonna need.
This code is limited with 100 as the maximum number of students,.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.