Oke,
Next attempt :
Code:
#include <iostream>
#include <cstring>
#include <sstream>
#include <fstream>
using namespace std;
int input_games()
{
string home_team , away_team, game ;
int lengte ;
do
{
cout<< "Home team :"; // inlezen van de team die thuis speelt
getline(cin,home_team);
lengte = home_team.length() ; // controle of de gebruiker iets ingevoerd heeft
if (lengte==0)
{
cout<< "input is empty. There must be a input";
}
}
while (lengte==0);
do
{
cout<< "Away team :"; // inlezen van het uitspelende team
getline(cin,away_team);
lengte = away_team.length() ; //controle of de gebruiker iets ingevoerd heeft
if (lengte==0)
{
cout<< "input is empty. There must be a input";
}
}
while (lengte==0);
int home_score;
for (;;)
{
cout << "Enter the home score: "; // Inlezen van de soore van de thuisspelende team
string line;
getline(cin, line);
stringstream ss(line);
if (ss >> home_score && ss.eof()) // controle of er alleen cijfers zijn ingevoerd
{
break;
}
else
{
cout << "Invalid input: enter a number only.\n";
}
}
int away_score;
for (;;)
{
cout << "Enter the away score: "; // invoeren van de score van het uitspelende team
string line;
getline(cin, line);
stringstream ss(line);
if (ss >> away_score && ss.eof()) // controle of er alleen maar cijfers zijn ingevoerd
{
break;
}
else
{
cout << "Invalid input: enter a number only.\n";
}
}
ofstream a_file ( "test.txt"); // open de tekstfile and zet de gegevens erin
a_file << home_team << ";" << away_team << ";" << home_score << ";" << away_score ;
a_file.close() ;
return 0;
}
string get_user_input() // invoeren van de keuze van het hoofdmenu
{
string input;
do
{
cout<<"1) Input game.: "<<endl;
cout<<"2) Making the rank.: "<<endl;
cout<<"3) Quit.: "<<endl;
getline(cin, input);
if ( input!="1" && input!="2" && input!="3" )
{
cout<< "Input must be 1 or 2 or 3" <<endl;
}
}
while ( input!="1" && input!="2" && input!="3"); // while not 1, 2, or 3
return input;
}
int main(){
string input ;
do
{
input = get_user_input();
if( input == "1" )
{
input_games(); // als de gebruiker 1 kiest ga dan naar invoeren van de wedstrijdgevens
}
else
if( input == "2" )
{
/* do whatever */
}
} // als de gebruiker 2 kiest , ga dan naar het maken van de stand
while (input!="3"); // laat het menu zien zolang de gebruiker geen 3 kiest
return 0;
}
Roelof