10-25-2010, 02:10 PM
(10-25-2010, 12:37 PM)Reality Wrote: Is it possible in c++ to allow the person to type the sign they choose>?
Like in pythonI think you can do
print "Choose blah blah"
if input = ""
etc?
sorry for typing my lapop broke and im on a netbook
Yes, absolutely. The easiest thing would be to store the input as a char (a 1 byte data type that can store a single character such as 'a'). You could also bring in the C++ string library and store the input as a string. The string library overloads the equal to operator (==) to allow for comparing two strings.
Char
Code:
#include <iostream>
int main ()
{
std::cout << "Enter a character: ";
char input;
std::cin >> input;
if (input == 'a')
{
std::cout << "You entered the letter A." << std::endl;
}
return 0;
}
String
Code:
#include <iostream>
#include <string>
int main ()
{
std::cout << "Enter a character: ";
std::string input;
std::cin >> input;
if (input == "something")
{
std::cout << "You said something." << std::endl;
}
return 0;
}
Ho, ho, ho! Well, if it isn't fat stinking billy goat Billy Boy in poison!
How art thou, thou globby bottle of cheap, stinking chip oil?
Come and get one in the yarbles, if ya have any yarbles, you eunuch jelly thou!
How art thou, thou globby bottle of cheap, stinking chip oil?
Come and get one in the yarbles, if ya have any yarbles, you eunuch jelly thou!