Safe proofing Program

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 11
Reputation: Beemer is an unknown quantity at this point 
Solved Threads: 0
Beemer Beemer is offline Offline
Newbie Poster

Safe proofing Program

 
0
  #1
May 23rd, 2008
Hi all , I have successfully written a simple program to calculate the total points scored by backs and forwards against one another in a 18 person team, but I need to safe proof it against a person entering anything other than F/f for forwards or B/b for backs , if something else is input I need the program to ask the user the (Enter F for forwards and B for Backs: ) question again untill an appropriate input is recieved, I thought of a do while statment in my (void inputAndValidate) section around that question but it doesnt seem to work, could anybody help ? Here is my code bellow

  1.  
  2. //Assignment 3 Question 5A
  3. #include <iostream>
  4. #include <string>
  5. using namespace std;
  6.  
  7. void updateCorrectTotal (char & position, int & points, int & totForward, int & totBack)
  8. {
  9.  
  10. if (position == 70 || position == 102)
  11. totForward = (totForward + points);
  12. if (position == 66 || position == 98)
  13. totBack = (totBack + points);
  14.  
  15.  
  16. }
  17.  
  18.  
  19. void inputAndValidate (char & position, int & points)
  20. {
  21.  
  22. cout << " This program will calculate the total amount of points scored by forwards" << endl;
  23. cout << " Against the total number of points scored by Backs." << endl;
  24. cout << " " << endl;
  25. cout << " Please Enter your 18 players positions followed by there points scored." << endl;
  26. cout << " " << endl;
  27.  
  28. cout << " Enter F for forwards and B for Backs: ";
  29. cin >> position;
  30.  
  31.  
  32. cout << " Enter the number of points scored by the player: " ;
  33. cin >> points;
  34.  
  35.  
  36. }
  37.  
  38.  
  39. int main()
  40. {
  41.  
  42. char position;
  43. int points, totForward, totBack;
  44.  
  45. totForward = 0;
  46. totBack = 0;
  47.  
  48. for (int i = 1; i <= 18; i++)
  49. {
  50. inputAndValidate (position, points);
  51.  
  52. updateCorrectTotal (position, points, totForward, totBack);
  53. }
  54. cout << " Total number of points scored by forwards: "
  55. << totForward << endl;
  56. cout << " Total number of points scored by backs: "
  57. << totBack << endl;
  58.  
  59.  
  60. return 0;
  61. }
  62. ]
Last edited by Ancient Dragon; May 23rd, 2008 at 8:41 am. Reason: add code tags and removed color tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,670
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Safe proofing Program

 
0
  #2
May 23rd, 2008
just put lines 28 and 29 in a loop. After line 29 add an if statement to validate data imput. If its ok then exit the loop.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 11
Reputation: Beemer is an unknown quantity at this point 
Solved Threads: 0
Beemer Beemer is offline Offline
Newbie Poster

Re: Safe proofing Program

 
0
  #3
May 23rd, 2008
Thanks very much dont know why I couldnt get that must be because its friday, will make sure code is input correctly next time , Thanks
Last edited by Beemer; May 23rd, 2008 at 8:58 am.
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the C++ Forum


Views: 280 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC