Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This program is suppose to ask the user how many students how many grades then ask for student name and student grades then gather the information and display the name and the grade and the average and the total average for the class.
I have gotten this far but the last set of arrays is not working thanks for the help.


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

int main(){

int numgrade;
int numstudent;
const int max_students = 499;
const int max_grade = 499;
string student [max_students];
int students [max_students][max_grade] = {0,0};
int grade;

cout << "Enter the number of students: ";
cin >> numstudent;

cout << "Enter the number of grades: ";
cin >> numgrade;
for (int curstudent =0; curstudent < numstudent; curstudent++){
	
	cout << "Enter the students name: ";
	cin >> student[curstudent];
    
	for (int curgrade =0; curgrade < numgrade; curgrade++){
        cout << "Enter the grade: ";
		cin >> student[curgrade];
	}
}

student [0] = 100;
student [1] = 75;
student [2] = 50;
student [3] = 25;

for (int curstudent =0; curstudent < numstudent; curstudent++){
		for (int curgrade =0; curgrade < numgrade; curgrade++){
       	cout << student [0] << endl;
		cout << student [1] << endl;
		cout << student [2] << endl;
		cout << student [3] << endl;
	}
}
system("pause");
return 0;
}
Posted
Updated 22-Oct-10 2:23am
v2

Well the logic is not correct..
whats happening with the first two set of for loops is that:

in the first loop :
for (int curstudent =0; curstudent < numstudent; curstudent++){

cout<< "Enter the students name: ";
cin >> student[curstudent];

here the value in the student array is being entered.

but in the second "for" loop,

again you are entering the values in the array starting from 0(the index),
so each time u loop the values that you entered from the first loop,it gets overwritten with values from the second loop.

So you have to change your logic!
 
Share this answer
 
v3
Comments
Tarun.K.S 22-Oct-10 9:04am    
i am not able to understand your question but i think you can use a 2-dimensional array to store the student name and his/her grades.
EDITH GINGRAS 22-Oct-10 9:10am    
ok now I am confused what do you mean by logic and where are you speaking about the names and the grades and the num grades and the num student part of this is working fine its the other part that is not working that is the problem sorry I am not good at explaining what I needed the help with the problem begins when I try to get the name, grade and average in a table like format using the array. Or is this already there and all I need is to add the total average grade for student array to the print out and then just get the total average of the class array to print out the results? ok I think Im on to something here but I could be wrong thanks any more help on this is appreciated
William Winner 22-Oct-10 12:24pm    
I like that...."what do you mean by logic?"
EDITH GINGRAS wrote:
string student [max_students];
int students [max_students][max_grade] = {0,0};

Warning: the variable 'students' has really a silly name ('grades' would be better, IMHO).


EDITH GINGRAS wrote:
for (int curstudent =0; curstudent < numstudent; curstudent++){

cout << "Enter the students name: ";
cin >> student[curstudent];

for (int curgrade =0; curgrade < numgrade; curgrade++){
cout << "Enter the grade: ";
cin >> student[curgrade];
}
}

Wrong, change to
for (int curstudent=0; curstudent < numstudent; curstudent++)
{
  cout << "Enter the students name: ";
  cin >> student[curstudent];
  for (int curgrade=0; curgrade < numgrade; curgrade++)
  {
    cout << "Enter the grade: ";
    cin >> students[curstudent][curgrade];
  }
}



EDITH GINGRAS wrote
:student [0] = 100;
student [1] = 75;
student [2] = 50;
student [3] = 25;

Wrong: remove such bogus lines.


EDITH GINGRAS wrote:
for (int curstudent =0; curstudent < numstudent; curstudent++){
for (int curgrade =0; curgrade < numgrade; curgrade++){
cout << student [0] << endl;
cout << student [1] << endl;
cout << student [2] << endl;
cout << student [3] << endl;
}
}

Wrong: change to
for (int curstudent=0; curstudent < numstudent; curstudent++)
{  
  cout << student [curstudent] << endl;
  for (int curgrade=0; curgrade < numgrade; curgrade++)
  {
     cout << students[curstudent][curgrade] << endl;   
  }
}




BTW why are you using fixed-size arrays, instead of, for instance, the std::vector class?
:)
 
Share this answer
 
Comments
EDITH GINGRAS 22-Oct-10 9:44am    
thanks I was going to change that anyways but besides that I tried this avenue and when I try to run it I get the on consol numgrades numstudents curstudent curgrade but then I get a bunch of dk2-> pointing in a downward row. I found this not to work properly prior to your post so I thought I should try another way and yes it is a fixed size I donot know about that class yet thanks
EDITH GINGRAS 22-Oct-10 22:49pm    
ok got things to work for that now how would I get the student average to display? I know the curgrades needs to be divided by the numgrades but this does not work when implemented curgrade reads under defined so how would I define it to work ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900