got prob with this small program

This is a discussion on got prob with this small program within the C++ Programming forums, part of the General Programming Boards category; Hi, this is a really small crappy thing that tons of people have done so i thought id give it ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    132

    got prob with this small program

    Hi, this is a really small crappy thing that tons of people have done so i thought id give it a go lol.

    i thought it looked ok but it wont work.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	int age;
    	int answer;
    	int x = 4;
    	int z;
    
    	cout << "Cat or Dog?: \n";
    	cin >> z;
    
    	if(z == Cat || cat || CAT || CAt || CaT || cAT || caT || cAt);
    	{
    		cout << "Ok, enter the cats age: ";
    		cin >> age;
    
    		(answer = age * x);
    
    		cout <<"Your cat is: \n";
    			cout << answer;
    			cout<<"in cat years\n" << endl;
    	}
    	if(z == Dog || dog || DOG || DOg || DoG || DoG || dOG || doG);
    	{  cout << "Ok, enter the dogs age: ";
    	cin >> age;
    
    	(answer = age * x);
    
    	cout <<"Your dog is: \n";
    	cout << answer;
    	cout <<"in dog years!\n" << endl;
    	}
    
    	else
    	{
    		cout <<"That is not a cat or dog fool!" << endl;
    	}
    	system("PAUSE");
    	return 0;
    }
    error is
    Code:
    ------ Build started: Project: mine, Configuration: Debug Win32 ------
    Compiling...
    mine.cpp
    .\mine.cpp(15) : error C2065: 'Cat' : undeclared identifier
    .\mine.cpp(15) : error C2065: 'cat' : undeclared identifier
    .\mine.cpp(15) : error C2065: 'CAT' : undeclared identifier
    .\mine.cpp(15) : error C2065: 'CAt' : undeclared identifier
    .\mine.cpp(15) : error C2065: 'CaT' : undeclared identifier
    .\mine.cpp(15) : error C2065: 'cAT' : undeclared identifier
    .\mine.cpp(15) : error C2065: 'caT' : undeclared identifier
    .\mine.cpp(15) : error C2065: 'cAt' : undeclared identifier
    .\mine.cpp(26) : error C2065: 'Dog' : undeclared identifier
    .\mine.cpp(26) : error C2065: 'dog' : undeclared identifier
    .\mine.cpp(26) : error C2065: 'DOG' : undeclared identifier
    .\mine.cpp(26) : error C2065: 'DOg' : undeclared identifier
    .\mine.cpp(26) : error C2065: 'DoG' : undeclared identifier
    .\mine.cpp(26) : error C2065: 'dOG' : undeclared identifier
    .\mine.cpp(26) : error C2065: 'doG' : undeclared identifier
    .\mine.cpp(37) : error C2181: illegal else without matching if
    Build log was saved at "file://c:\Documents and Settings\Reece.LAPTOP\My Documents\Visual Studio 2005\Projects\mine\mine\Debug\BuildLog.htm"
    mine - 16 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    sorry, but im learning still and it is really bugging me.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >if(z == Cat || cat || CAT || CAt || CaT || cAT || caT || cAt);
    The only thing that exists in this is z. You need to define a name before you use it, unless you think your compiler knows that a cat is in varying cases. Also, the logical OR operator doesn't work like that. You need to compare with z for every part. Also also, if statements don't end with a semicolon.
    My best code is written with the delete key.

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    You can't use names like that the compiler thinks that they are variable names. Seconde you are using a int to take in string input you will want to #include <string> and change the int z to string z. And then when you are comparing you want to use "" so if(z == "cat) etc..
    Woop?

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    The user's answer to the first question should be a string. A standard string, in lower case or something.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    903
    You have many errors there. The biggest is that you are trying to get a string in input with an integer variable. Another big one is that you think you can compare that variable to strings and another big one is that you never put strings in quotations marks. You have too many errors and I don't want to spend that much time on your question, I'll just tell you that you should really review your basics. I don't want to sound mean, but lots of parts are just really off. I suggest you read my article here : http://code-dynasty.net/articles/C_A...Programming/78. Also, you should use std::string, it would greatly help you as I doubt you have learned arrays. You will also need to use tolower(). Google it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gradebook Program - Small Problem, Need Assistance
    By CaitlynCraft in forum C Programming
    Replies: 1
    Last Post: 11-13-2007, 08:51 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  4. Program to reverse a number. small error with it..
    By comproghelp in forum C Programming
    Replies: 8
    Last Post: 11-22-2004, 09:52 AM
  5. Help writing small program
    By guitarhead2000 in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2004, 12:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21