thanks but i still can,t do it , i tried that but i think in a wrong way ,
// *******add do or do while loop in it , because u dont want the user to excute again to make the user guess correctly.
#include <iostream>
#include <cstring>
using namespace std;
int main ()
{
char szKey[] = "orange";
char szInput[80];
do {
cout <<" Guess What is my favourite fruit? ";
cin >> szInput ;
#include <iostream>
#include <string>
#include <cstring>
usingnamespace std;
int main ()
{
string szKey = "orange";
string szInput;
do {
cout <<" Guess What is my favourite fruit? ";
getline(szInput, cin); // Allows for multiple word answers e.g. Passion fruit
if (szInput == szKey){ // If Key and Input equal
cout << "Correct answer!\n";} // Print correct answer
else {
cout << "oooooppppppss !!!wrong answer\n";
};
while ( szInput != szKey); // Do UNTIL right answer is got i.e. repeat while Input is not equal to szKey
return 0;
}
you should #include <string> and use std::strings instead of char arrays, the only things that will need to change are that youll need to use getline() rather than cin to take input, and you dont need to use strcmp any more you can compare two strings with the == operator.
Ah; rookie error on my part - when I used getline I had the arguments the wrong way round.
Error #1: Getline takes the input stream (cin) as the first argument and variable as the second. So if you want the input to be taken as a string input change the getline statement: getline(cin, szInput); // Allows for multiple word answers e.g. Passion fruit
Error #2: Program ends before closing brace - add another } where required