943,719 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 666
  • C RSS
Nov 3rd, 2008
0

Big looping problem in C - help

Expand Post »
Hey Guys!
I have a weired one here, it must be a post-test loop, and here is how result has to look like:



Enter the Section Code: 0

Invalid value entered. Must be 1 to 4, please re-enter: 1

Enter the Student's ID: 456789

Enter mark#1: 10

Enter mark#2: -20

Invalid grade entered. Must be 0.0 to 100.0, please re-enter: 20

Enter mark#3: 5.5

Enter mark#4: 5

Enter mark#5: 10

Enter mark#6: 6

Enter mark#7: 7

000456789's total mark is: 63.5


Enter the Student's ID ['0' to quit]: 123654987

Enter mark#1: 1

Enter mark#2: 2

Enter mark#3: 3

Enter mark#4: 4

Enter mark#5: 5

Enter mark#6: 6

Enter mark#7: 7
123654987's total mark is: 28.0


Enter the Student's ID ['0' to quit]: 0

The average for the section is 45.75%


Enter the Section Code [0 to quit]: 5

Invalid value entered. Must be 0 to 4, please re-enter: 2

Enter the Student's ID: 987654

Enter mark#1: 7

Enter mark#2: 6

Enter mark#3: 5

Enter mark#4: 4

Enter mark#5: 3

Enter mark#6: 2

Enter mark#7: 1

000987654's total mark is: 28.0


Enter the Student's ID ['0' to quit]: 0

The average for the section is 28.00%


Enter the Section Code [0 to quit]: 0


The average for the course is 39.83%


i got everything working except looping the main sequence, take a look at my results:


Enter the Section Code:44

Invalid value entered. Must be 1 to 4, please re-enter:1


Enter Student's ID:11

Enter Mark#1:5
Enter Mark#2:5
Enter Mark#3:5
Enter Mark#4:5
Enter Mark#5:5
Enter Mark#6:5
Enter Mark#7:5
000000011's total mark is: 5.0

Enter Student's ID[0 to Quit]:0


Enter the Section Code[0 to quit]:3

Enter Mark#1:

everything works fine if i hit 0 at "Enter the Section Code[0 to quit]:"
but just like the log shows, when i hit anything but 0 it goes to "Enter Mark1:" instead of "Enter Students ID:", i just cant loop it properly.,
here comes my code a part of my main():

  1. section=PreSecCode();
  2. student_id=PreStudentId();
  3.  
  4. do
  5. {
  6. do
  7. {
  8.  
  9. mark=Mark();
  10. PrintIt(student_id, mark);
  11.  
  12. student_id=StudentId();
  13. }while(student_id!=0);
  14.  
  15. section=SecCode();
  16.  
  17. }while(section!=0);


any help would be greatly appreciated!!
chheers
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atman is offline Offline
50 posts
since Oct 2008
Nov 4th, 2008
0

Re: Big looping problem in C - help

Is your program accepting integers as well as strings(letters)?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Nov 4th, 2008
0

Re: Big looping problem in C - help

Click to Expand / Collapse  Quote originally posted by iamthwee ...
Is your program accepting integers as well as strings(letters)?
integers only
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
atman is offline Offline
50 posts
since Oct 2008
Nov 4th, 2008
0

Re: Big looping problem in C - help

Identify the portion of the code that isn't working and explain what it is supposed to do and I will gladly try to help you. Also, if we're supposed to identify your problem based on that 100 lines of input & output and that small segment of code, how are we going to do so if you didn't post the code for your functions that were called in that segment of code?
Reputation Points: 874
Solved Threads: 352
Posting Maven
BestJewSinceJC is offline Offline
2,758 posts
since Sep 2008
Nov 4th, 2008
0

Re: Big looping problem in C - help

The problem is that your outer loop is checking for 0 to exit. So when you have an error condition you are exiting the loop. Is there a char you enter to exit the program? That's the value that you'll want to use in that loop. I think you'll want to do something like this...
  1. while(c != SENTINAL){
  2. if(c == 0){
  3. PrintIt("error must be 1-4");
  4. continue;
  5. }
  6. //other loop code
  7. }
SENTINAL is the value the user enters to exit your program
Reputation Points: 10
Solved Threads: 6
Newbie Poster
bionicseraph is offline Offline
19 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: XHTML Parser in C code
Next Thread in C Forum Timeline: o s development in c. how?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC