I started to learn C++ some hours ago. Long ago I learned Pascal and I remembered one of my first tutorial programs, so I started to code it in C++ too.
The program is about guessing a number.
#include <iostream>
int main()
{
int guess, number, error, tries;
char answer;
tries = 0;
do
{
tries++;
number = rand();
std::cout << "I think of a number. Guess it!";
std::cout << "\nYour Guess: ";
std::cin >> guess;
do
{
if (guess > number)
{
std::cout << "The number is smaller!\n";
std::cout << "New guess: ";
std::cin >> guess;
}
if (guess < number)
{
std::cout << "The number is bigger!\n";
std::cout << "New guess: ";
std::cin >> guess;
}
}while(guess != number);
std::cout << "\nCongratulations! You won!\nNumber of tries: " << tries;
do
{
std::cout << "\nDo you want to play again?(y/n) ";
std::cin >> answer;
if (answer != "n" || answer != "N" || answer != "y" || answer != "Y")
{
std::cout << "Error! Please reply only with the 'y' or 'n' button!\n(Help: y means yes, n means no.)";
error = 1;
}
else
{
error = 0;
}
}while(error == 1);
}while(answer == "y" || answer == "Y");
return 0;
}
Errors I get when I debug at every line where I try to use (answer == "*char*") or (answer != "*char*")
error C2040: 'int' differs in levels of indirection from 'const char [2]'
error C2446: no conversion from 'const char *' to 'int'
I'd be glad if someone could help me!
Thanks in advance