Hello!
I am having a couple of problems with an assignment I've been given. Coule you please give me a hand so that I can finish it?
1) [SOLVED] I want to confirm when a user inputs a number, for it not to be a letter.
1 2 3 4 5 6 7 8
|
int amount
cout<<"Input amount"<<endl;
cin>>amount
/*and here's where I want to check that it's a number and not a letter, displaying "Please make sure to type a value between 1 and 200." or something alike.
What I thought is
"if amount not in (1..200) {}
else (...)*/
|
How could I?
2)[SOLVED, BUT HAS A MINOR ISSUE] I'm trying to get my program to write a text file when certain conditions are met, but the compiler (IDE?) keeps telling me there's a typo
(|43|error: expected primary-expression before ';' token|) on the lines that start with "case".
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
void escrituraResultados (int ganador, string player1, string player2,int turnosRemanentes,int turnosDisponibles, string palabraaAdivinar)
{
fstream resultados ("Resultados.txt");
if (resultados.is_open())
{
/*switch (ganador)
{
case 1: resultados << player1<<" ganó. La palabra secreta era "
<<palabraaAdivinar<<"."<<endl<<;
resultados << "Se le dio a "<<player2<<" "<<turnosDisponibles<<endl;
resultados.close();
break;
case 2: resultados << player2<<" adivinó la palabra secreta ("<<palabraaAdivinar<<")."<<endl<<;
resultados << "Se le dieron "<<turnosDisponibles<<" turnos, y le sobraron "<<turnosRemanentes<<endl;
resultados.close();
break;
}*/
}
else cout << "Can't open file.";
}
|
What's wrong there? I can't see the error...
3)[SOLVED] Lastly, I want to know how could I make sure that a string the user inputs is stored in memory, is stored entirely in lowercase.
(User inputs <<HoUSe>>, program interprets <<house>>)
I know of the tolower function, but I don't know if it's right... or how to use it.
Any help'd be greatly appreciated!