correct my algorithm for average problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 8
Reputation: lavicool is an unknown quantity at this point 
Solved Threads: 0
lavicool lavicool is offline Offline
Newbie Poster

correct my algorithm for average problem

 
0
  #1
Oct 12th, 2006
Hi all,

I just joined the post. Iam new to C programming. I have a question regarding a problem i found in some book. The problem is i have a input file with student ID, 5 program scores, midterm and final score. i have to check for wrong input of data(negative score),calculate average score for program,calculate student totalscore (30% of programming,30% midterm,35%final and 5%free for whoever takes final exam),give grade to student and then finally compute calss total score.

print in a format (sID,sc1,sc2,sc3,sc4,sc5,midterm,final,total, grade) to the output file.

My idea looks very simple to the problem. I think it may not that simple as i think. Please guide me.

-First we have to scan the details from input file
-if the score is > 0 and < 100 then
1)calculate average score for programs (total all score and divide by 5)
2) student total score i.e 30%*total program score+35%midterm+35%*final+5%
Else
display "the score is not a valid one"
3)calculating grade
If Marks >=90 and <=100 then
Display grade = ‘A’

Else if marks >= 80 and <=89 then
Display grade = ‘B’

Else if marks >= 70 and <=79 then
Display grade = ‘C’

Else if marks >= 60 and <=69 then
Display grade = ‘D’

Else if marks >=0 and <=59 then
Do display grade = ‘F’

4) calculate total class score

Please let me know if iam right. If possible please tell me how to start writing C code for this or the pseudocode

Thanks for your help
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,610
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 464
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: correct my algorithm for average problem

 
0
  #2
Oct 12th, 2006
Hmmm almost there.
You just need to change
if the score is > 0 and < 100 then
Why cant the score be 100 ?

Just loop through the scores, and at the same time check for the above condition, if not satisfied duck out of the program using "exit (1)" or just consdier the score as 0 and move on.

And to start off programming there are many basic tuts on the C language in the forum sticky at the top of C++ forum here.

Or if you know a bit of C just post what you can do and we will try to help you out.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: correct my algorithm for average problem

 
0
  #3
Oct 12th, 2006
You also don't need the range in the IF's. For example
  1. IF score > 90 ; this will take everything above 90...
  2. Display A ; Output grade and the IF is over
  3. else
  4. IF score > 80 ; this will take everything above 80...
  5. Display B ; anything above 90 has already been taken care of above
  6. else
  7. ...
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 8
Reputation: lavicool is an unknown quantity at this point 
Solved Threads: 0
lavicool lavicool is offline Offline
Newbie Poster

Re: correct my algorithm for average problem

 
0
  #4
Oct 12th, 2006
Thanks for your reply. How do I calculate for all the 5 students and store their individual score and then total it up outside the loop? I think i need to store them in some variable. There is where i get stuck and cannot proceed further.

thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 8
Reputation: lavicool is an unknown quantity at this point 
Solved Threads: 0
lavicool lavicool is offline Offline
Newbie Poster

Re: correct my algorithm for average problem

 
0
  #5
Oct 12th, 2006
Thanks for your reply too. I did write a program like u said. But i don't want it to take value beyond 100 i.e 101 or 102..... so that is reason i put them in the range.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: correct my algorithm for average problem

 
0
  #6
Oct 15th, 2006
Originally Posted by lavicool View Post
Thanks for your reply too. I did write a program like u said. But i don't want it to take value beyond 100 i.e 101 or 102..... so that is reason i put them in the range.
So your first IF is at 100 and you output an error.

Originally Posted by lavicool View Post
Thanks for your reply. How do I calculate for all the 5 students and store their individual score and then total it up outside the loop? I think i need to store them in some variable. There is where i get stuck and cannot proceed further.
What do you know about arrays?
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 8
Reputation: lavicool is an unknown quantity at this point 
Solved Threads: 0
lavicool lavicool is offline Offline
Newbie Poster

Re: correct my algorithm for average problem

 
0
  #7
Oct 16th, 2006
Originally Posted by WaltP View Post
So your first IF is at 100 and you output an error.


What do you know about arrays?


Hi,

Thanks all for the help. I did finish writing my program this week
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC