Hey, as you can see I am a beginner at c++ and although I think I am improving I am still finding functions quite hard to get my head around. I am writing this program to test typing speed but am stuck at the beginning.
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
usingnamespace std;
int players ()
{
cout << "\nTyping Speed Test\n\n"
<< "See who is a faster typer out of your friends!\n"
<< "Would you like to start a one or two player game?\n"
<< "1) One Player\n2) Two Player\n\n";
int choice = 0;
while (choice != 1 && choice != 2)
{
cout << "Enter either 1 or 2: ";
cin >> choice;
}
return (choice);
}
string text ()
{
int choice = players ();
string numberPlayers;
if (choice == 1)
{
numberPlayers = "single player";
}
else
{
numberPlayers = "two player";
}
cout << "\nEnter the text that you will be typing in this "
<< numberPlayers << " game:\n\n";
}
int main()
{
text ();
return (0);
}
This is the output of the program.
Typing Speed Test
See who is a faster typer out of your friends!
Would you like to start a one or two player game?
1) One Player
2) Two Player
Enter either 1 or 2: 1
Enter the text that you will be typing in this single player game:
[/s]Run Command: line 1: 7551 Segmentation fault: 11 ./"$2" "${@:3}"
I'm not too sure what the error is at the end and how to solve it. Any help would be much appreciated, thanks in advance!
Hey, sorry for not making it clear. I seem to have located the problem to the two functions so I did not post the rest of the main function which has a return(0) and an other curly bracket. I will upload the rest now.