6 Replies - 1125 Views - Last Post: 31 October 2001 - 10:28 PM Rate Topic: -----

#1 miaka284  Icon User is offline

  • D.I.C Addict

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

help please........

Posted 30 October 2001 - 09:31 AM

someone please help me....
void add_record()
{
cout<<"how many student would you like to enter?"<<endl;
cin>>num;
cin.ignore(80,'
');
for(j=0; j<num;j++)
{
cout<<"Please enter full name"<<endl;
cin.get(fname[j],30);
cin.ignore(80,'
');
cout<<"Please the student's id number"<<endl;
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
  • +

Replies To: help please........

#2 VxJasonxV  Icon User is offline

  • D.I.C Head

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

Re: help please........

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.
Was This Post Helpful? 0
  • +
  • -

#3 blutrane  Icon User is offline

  • 私もクールです

Reputation: 25
  • View blog
  • Posts: 1,934
  • Joined: 17-May 01

Re: help please........

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 ;)
Was This Post Helpful? 0
  • +
  • -

#4 malkiri  Icon User is offline

  • D.I.C Regular
  • member icon

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

Re: help please........

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.
Was This Post Helpful? 0
  • +
  • -

#5 miaka284  Icon User is offline

  • D.I.C Addict

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

Re: help please........

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
Was This Post Helpful? 0
  • +
  • -

#6 VxJasonxV  Icon User is offline

  • D.I.C Head

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

Re: help please........

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.
Was This Post Helpful? 0
  • +
  • -

#7 blutrane  Icon User is offline

  • 私もクールです

Reputation: 25
  • View blog
  • Posts: 1,934
  • Joined: 17-May 01

Re: help please........

Posted 31 October 2001 - 10:28 PM

fixed and don't let your ego get the best of you jason
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1