advice with simple program for my girlfriend

AutopsyGuy (2)
I just started learning how to program earlier this semester. We started with Karel (easy I know :D ) and now we moved on to C++. I decided to try and make a small text program for my girlfriend just for fun. Basically I want it to ask her what her favorite animal is and have her type the word "bunny" and then have it display a picture message for her. I figured out how to prompt the question and display the message but I cant figure out how to make the program only accept the word bunny and have the program tell her to try again if she types in anything else. I know its a stupid program but any help would be appreciated!

Here is my program thus far:
as of right now it accepts any input :/

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
#include <iostream>
#include <string>
using namespace std;

void main ()
{
string bunny;

cout << "What is your favorite animal?" << endl;
cin >> bunny;
cout << "yay!" << endl;
cout << "(\\_/)" << endl << "(='.')" << endl << "o(\")(\")" << endl;
cout << "I Love You Bunny! <3" << endl;
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


I apologize if this problem has been answered before but all the solutions I find that kind of answer my question are pretty unclear to me :(
Last edited on
HiteshVaghani1 (187)
Just put getchar() after your code and that will work for you..
AutopsyGuy (2)
I followed your advice and added getchar () after my code but the compiler I'm using just tells me Found a regular identifier; a type name must appear here. Am I doing something wrong?
Stewbond (1670)
Remove \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ from the top and bottom of your code. If you do that, it compiles for me

cute...
What is your favorite animal?
bunny
yay!
(\_/)
(='.')
o(")(")
I Love You Bunny! <3
TheIdeasMan (1564)
void main ()

should be

int main ()

I am surprised your compiler accepted that.
Chervil (812)
Something like this:
1
2
3
4
5
6
7
8
9
10
    string animal;

    cout << "What is your favorite animal?" << endl;
    cin >> animal;
    while (animal != "bunny" && animal != "BUNNY" && animal != "Bunny")
    {
        cout << "That's a nice animal\nPlease enter another favourite animal:" << endl;
        cin >> animal;
    }
    cout << "that was a bunny";

See also: http://www.retrojunkie.com/asciiart/animals/rabbits.htm
Last edited on
Topic archived. No new replies allowed.