Dec 1, 2011 at 11:05pm UTC
void getData(int size, int [], int []);
void main(){
int Scores[5];
char Students [5][6];
int size;
cout << "Enter size for arrays: ";
cin >> size;
}
void getData(int testScore[],char studentName[]) {
int size;
int index;
cout << "Enter size for arrays: ";
cin >> size;
for (index = 0; index <= size -1; index++)
{
cout << "Enter" <<(index +1) << "th student name: "
<< ": ";
cin >> studentName[size];
}
for (index = 0; index <= size -1; index++)
{
cout << "Enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];
while (0 > testScore[index] || testScore[index] > 100){
cout << "Re-enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];
}
}
}
i got this now. IS this right?
Last edited on Dec 1, 2011 at 11:13pm UTC
Dec 1, 2011 at 11:32pm UTC
error C2087: 'abstract declarator' : missing subscript
error C2664: 'getData' : cannot convert parameter 3 from 'char [5][6]' to 'char [][1]'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
error C2087: 'studentName' : missing subscript
Errors!
Dec 1, 2011 at 11:34pm UTC
void getData(int size, int [], char [][]);
void main(){
int Scores[5];
char Students [5][6];
int size;
cout << "Enter size for arrays: ";
cin >> size;
getData(size,Scores,Students);
}
void getData(int size, int testScore[],char studentName[][]) {
int index;
for (index = 0; index <= size -1; index++)
{
cout << "Enter" <<(index +1) << "th student name: "
<< ": ";
cin >> studentName[index];
}
for (index = 0; index <= size -1; index++){
cout << "Enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];
while (0 > testScore[index] || testScore[index] > 100){
cout << "Re-enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];
}
}
}
Dec 1, 2011 at 11:43pm UTC
Ah, oops - I forgot one thing;
void getData(int size, int [], char [][]);
Change char [][]
to char [5][]
And the same here:
void getData(int size, int testScore[],char studentName[][]) {
Change char studentName[][]
to char studentName[5][]
Sorry for my mistake, I do not have a compiler to test myself.
Dec 1, 2011 at 11:48pm UTC
try void getData(int size, int [], char [][6]);
and void getData(int size, int testScore[],char studentName[][6]) {
Dec 1, 2011 at 11:49pm UTC
Are you sure? Can you copy and paste the errors (including the line numbers) and copy paste the code again?
Sorry for the inconvenience...
EDIT: Beaten by Peter87
Last edited on Dec 1, 2011 at 11:50pm UTC
Dec 1, 2011 at 11:52pm UTC
acutally nevermind it works. But i need to have it ask the name and then the test score. So like
Enter the 1th studnet name: John
Enter test score of john:100
So how would you change this code to make it do that up there?
void getData(int size, int [], char [][6]);
void sortData();
void main(){
int Scores[5];
char Students [5][6];
int size;
cout << "Enter size for arrays: ";
cin >> size;
getData(size,Scores,Students);
}
void getData(int size, int testScore[],char studentName[][6]) {
int index;
for (index = 0; index <= size -1; index++)
{
cout << "Enter" <<(index +1) << "th student name: "
<< ": ";
cin >> studentName[index];
}
for (index = 0; index <= size -1; index++){
cout << "Enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];
while (0 > testScore[index] || testScore[index] > 100){
cout << "Re-enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];
}
}
}
Last edited on Dec 2, 2011 at 12:03am UTC
Dec 2, 2011 at 12:04am UTC
Does it not do that already? What does it do currently?
Dec 2, 2011 at 12:05am UTC
It asks for all the names first and then it asks for all the test scores.
It has to ask the name of the first person and their test score after that.
Then ask for the second persons name and their test score. and so on
Dec 2, 2011 at 12:07am UTC
Enter size for arrays: 5
Enter 1th student name: John
Enter test score for John: -2
Re-enter test score for John: 109
Re-enter test score for John: 100
Enter 2th student name: Kathy
Enter test score for Kathy: 95
Enter 3th student name: Susan
Enter test score for Susan: 67
Enter 4th student name: Alice
Enter test score for Alice: 87
Enter 5th student name: Bill
Enter test score for Bill: 98
This is what its supposed to look like
Dec 2, 2011 at 12:08am UTC
Oh, I forgot.
To do that just put the code from the second for loop after the code inside thre first for loop, and get rid of the second for loop.
Dec 2, 2011 at 12:12am UTC
void getData(int size, int testScore[],char studentName[][6]) {
int index;
for (index = 0; index <= size -1; index++)
{
cout << "Enter" <<(index +1) << " th student name: "
<< ": ";
cin >> studentName[index];
for (index = 0; index <= size -1; index++){
cout << "Enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];
}
}
while (0 > testScore[index] || testScore[index] > 100){
cout << "Re-enter test score for " << studentName[index]
<< ": ";
cin >> testScore[index];
}
}
is this right?
Dec 2, 2011 at 12:15am UTC
1 2 3 4 5 6 7 8 9 10 11
for (index = 0; index <= size -1; index++)
{
cout << "Enter" <<(index +1) << " th student name: "
<< ": " ;
cin >> studentName[index];
for (index = 0; index <= size -1; index++){
cout << "Enter test score for " << studentName[index]
<< ": " ;
cin >> testScore[index];
}
}
Should be:
1 2 3 4 5 6 7 8 9 10 11
for (index = 0; index <= size -1; index++)
{
cout << "Enter" <<(index +1) << " th student name: "
<< ": " ;
cin >> studentName[index];
cout << "Enter test score for " << studentName[index]
<< ": " ;
cin >> testScore[index];
}
You don't want nested loops.
Last edited on Dec 2, 2011 at 12:16am UTC
Dec 2, 2011 at 12:18am UTC
okay now its works. Thansks. But now i have to do a bubble sort of for the array studentName in a fuction called sortData. And then return the data back to the main function
Dec 2, 2011 at 12:19am UTC
Do you know how bubble sort works? If not, look up examples first before attempting it with this.
Also, are you sorting by student name or student score?
Dec 2, 2011 at 12:21am UTC
I've got this so far. But its not right.
void sortData(int size, char studentName[][6]){
bool swap;
int temp;
do
{
swap = false;
for (int count = 0; count < (size - 1); count=++)
{
if (studentName[count] > studentName[count + 1])
{
temp = studentName[count];
studentName[count] = studentName[count +1];
studentName[count + 1] = temp;
swap = true;
}
}
} while (swap);
}
Last edited on Dec 2, 2011 at 12:23am UTC