| | |
Safe proofing Program
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 11
Reputation:
Solved Threads: 0
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
C++ Syntax (Toggle Plain Text)
//Assignment 3 Question 5A #include <iostream> #include <string> using namespace std; void updateCorrectTotal (char & position, int & points, int & totForward, int & totBack) { if (position == 70 || position == 102) totForward = (totForward + points); if (position == 66 || position == 98) totBack = (totBack + points); } void inputAndValidate (char & position, int & points) { cout << " This program will calculate the total amount of points scored by forwards" << endl; cout << " Against the total number of points scored by Backs." << endl; cout << " " << endl; cout << " Please Enter your 18 players positions followed by there points scored." << endl; cout << " " << endl; cout << " Enter F for forwards and B for Backs: "; cin >> position; cout << " Enter the number of points scored by the player: " ; cin >> points; } int main() { char position; int points, totForward, totBack; totForward = 0; totBack = 0; for (int i = 1; i <= 18; i++) { inputAndValidate (position, points); updateCorrectTotal (position, points, totForward, totBack); } cout << " Total number of points scored by forwards: " << totForward << endl; cout << " Total number of points scored by backs: " << totBack << endl; return 0; } ]
Last edited by Ancient Dragon; May 23rd, 2008 at 8:41 am. Reason: add code tags and removed color tags
![]() |
Other Threads in the C++ Forum
- Previous Thread: Design pattern for encode/decode modules
- Next Thread: retreive data from excel files
Views: 280 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






