Page 1 of 1

## 6 Replies - 1265 Views - Last Post: 31 October 2001 - 10:28 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=2388&amp;s=b52aec4c1927c4e7479335d334e6c67c&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 miaka284

Reputation: 0
• Posts: 530
• Joined: 10-May 01

Posted 30 October 2001 - 09:31 AM

```void add_record()
{
cout<<"how many student would you like to enter?"<<endl;
cin>>num;
cin.ignore(80,'
');
for(j=0; j<num;j++)
{
cin.get(fname[j],30);
cin.ignore(80,'
');
cin.get(id[j], 15);
cin.ignore(80, '
');
cout<<"Please enter 4 scores and press enter"<<endl;
for(i=0; i<4;i++)
{
cin>>scores[i];
cin.ignore(80, '
');
total[j]=total[j]+scores[i];}
total[j]=total[j]/4;
}
calculate();}
void calculate()
{if((total[j]>90)&&(total[j]<100))
{
letter[j]='A';
}
if((total[j]>80)&&(total[j]<89))
{
letter[j]='B';
}
if((total[j]>70)&&(total[j]<79))
{
letter[j]='C';
}
if((total[j]>60)&&(total[j]<69))
{
letter[j]='D';
}
if((total[j]>0)&&(total[j]<59))
{
letter[j]='F';
}
display_record();
}
void display_record()
{cout<<endl;
cout<<"Student"<<setw(10)<<"id#"<<setw(15)<<"Average"<<setw(15)<<"Letter"<<endl;
cout<<"------------"<<setw(10)<<"-------------"<<setw(10)<<"--------------"<<setw(10)<<"--------------"<<endl;
for(j=0;j<num;j++)
{
cout<<fname[j]<<setw(10)<<id[j]<<setw(15)<<total[j]<<setw(10)<<letter[j]<<endl;
}
questions();
}

```

this is my gradebook program... hmm... it only prints out the average for the last number if I did multiple inputs of student's scores.... and it only prints out when the student have f.....so I don't know what to do...

Is This A Good Question/Topic? 0

### #2 VxJasonxV

Reputation: 1
• Posts: 201
• Joined: 03-October 01

Posted 30 October 2001 - 03:58 PM

Quote

```for(j=0;j<num;j++)
{
cout<<fname[j]<<setw(10)<<id[j]<<setw(15)<<total[j]<<setw(10)<<letter[j]<<endl;
}
questions();
}
```
I'm very sure that the problem is because you're outputting just a certain part of the array.  Try getting rid of the for loop (for the output) and the [j]'s too...  Your line should be:
```cout<<fname<<setw(10)<<id<<setw(15)<<total<<setw(10)<<letter<<endl;
questions();
```
And then...why are you storing letter to an array?  You have letter[j] but no for loop...also, you're only storing one letter, so you don't need an array.  And as Hanosh was telling my class today.  Effective, Efficiently Structured Code. Also, in your letter calculations, you're putting total[j], even though you still aren't using a for loop...since total was already calculated (and stored in total) all you need to do is use total, no array. You need some fixer uppers.
```void calculate()
{
if((total>=90)&&(total<=100)){letter='A';}
if((total>=80)&&(total<=89)){letter='B';}
if((total>=70)&&(total<=79)){letter='C';}
if((total>=60)&&(total<=69)){letter='D';}
if((total>=0)&&(total<=59)){letter='F';}
}
```
Everything else looks good though.

### #3 blutrane

• 私もクールです

Reputation: 26
• Posts: 1,934
• Joined: 17-May 01

Posted 30 October 2001 - 10:49 PM

its for multiple records at one 'running'...
and if you looked carefully  you would see where the for loop was ;)

### #4 malkiri

• D.I.C Regular

Reputation: 3
• Posts: 364
• Joined: 29-March 01

Posted 31 October 2001 - 08:33 AM

Not sure if this has been resolved already, but the problem is with the lack of for loop. The output part seems to be fine as it is.

### #5 miaka284

Reputation: 0
• Posts: 530
• Joined: 10-May 01

Posted 31 October 2001 - 09:26 AM

well.. jason.. the for loops is for printing out multiple users... but my average is printing out screwy.. cuz it either prints out the right average for the last account and it prints out the last number for the first account... or it prints out wrong average.. and if you check my program.. the formulas are right.. but the numbers came out weird

### #6 VxJasonxV

Reputation: 1
• Posts: 201
• Joined: 03-October 01

Posted 31 October 2001 - 03:42 PM

Malkiri proved my point.  I'm sorry...I didn't mean to say the output was wrong...anyways, that wasn't what the overall problems are.  The things I found were when calculating the letter, you are calling total[j] which is not a good thing.  Cause j will always be 0, because (and this is for clarification purposes, don't get mad Miaka) IN THE CALCULATE FUNCTION there is no for loop.  And you've already calculated what total is, so you don't need to use total[j] unless you put in a for loop, which again you do not have in the calculate function.

### #7 blutrane

• 私もクールです

Reputation: 26
• Posts: 1,934
• Joined: 17-May 01