Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 01-03-2006, 02:43 PM   #1
Baseband Member
 
Dnsgm's Avatar
 
Join Date: Jan 2006
Posts: 61
Default C++ help

It's a simple program but somehow it doesn't go on after the switch command. Ya, so some help would be great.


Code:
#include <iostream>
using namespace std;

class cat
{
      public:
             char name[50];
             char eyeclr[15];
             char fur[15];
             
             int itsage;
             float itsweight;
             
             void meow();
};
void meow(){
     cout<< "Meow\n\n";
};                              

int addition (int a, int b)
{
    int c;
    c = a + b;
}
int subtraction (int a, int b)
{
    int c;
    c = a - b;
}
int multiply (int a, int b)
{
    int c;
    c = a * b;
}

int division (int a, int b)
{
    int c;
    c = a / b;
}

int main()
{
    cat cx;
    char action[30];
    
    cout<< "Make your own cat.\n" <<endl;
    cout<< "What's its name?: ";
    cin>>cx.name;
    cout<< endl;
    
    cout<< "What's its eye color?: ";
    cin>>cx.eyeclr;
    cout<<endl;
    
    cout<< "What's its fur color?: ";
    cin>>cx.fur;
    cout<< endl;
    
    cout<< "Hi, " <<cx.name << " who has the eye color of ";
    cout<< cx.eyeclr << " and who has " << cx.fur << " colored fur.\n";
    
    cout<< "How old is it?: ";
    cin>>cx.itsage;
    cout<< endl;
    
    cout<< "How much does it weigh?: ";
    cin>>cx.itsweight;
    cout<< endl;
    
    cout<< "So it's " <<cx.itsage << " and it's " << cx.itsweight << ", cool.\n";
    cout<< endl;
    
    cout<< "What would you like " << cx.name << " do?: \n";
    cout<< "bark\nmeow\nor quack\n";
    cin>> action;
    cin.ignore();
    cout<< endl;
    
    if (action == "bark" || "BARK" || "Bark") cout<< "Cats can't bark, dogs can!\n";
    else if (action == "meow" || "MEOW" || "Meow") cout<< "Meow\n";
    
    else {
         cout<< "Cats can't quack! Ducks can!\n";
         }
}
    
    char ans1[10];
    
    cout<< "Would you like to teach mathematics to it? (y or n): \n";
    cin>> ans1;
    
    if (ans1 == "y") {
             
             char form;
             int t1, t2, t3, t4, t5, t6, t7, t8, t9, t10;
             char learn[10];
             
             
             cout<< "Choose a formula: ";
             cout<< endl << "addition\n";
             cout<< "subtraction\n";
             cin>> form;
             cin.ignore();
             
             switch ("addition" || "subtraction")
             {
                    case 0:
                         cout<< "Let's just stick between 1 and 10. (1+1=2, 1+2=3 format only): \n";
                         cin>>t1;
                         cout<< endl;
                         cin>>t2;
                         cout<< endl;
                         cin>>t3;
                         cout<< endl;
                         cin>>t4;
                         cout<< endl;
                         cin>>t5;
                         cout<< endl;
                         cin>>t6;
                         cout<< endl;
                         cin>>t7;
                         cout<< endl;
                         cin>>t8;
                         cout<< endl;
                         cin>>t9;
                         cout<< endl;
                         cin>>t10;
                         cout<< endl;
                         cout<< endl;
                         
                         cout<< cx.name << " has learned all that, but sadly I don't think he can learn anymore.\n";
                         cout<< "would you like to see what he has learned? (y or n)\n";
                         cin>>learn;
                         
                         if (learn == "y"){
                                   cout<< "Show us what you know " <<cx.name;
                                   
                                   void meow();
                                   
                                   cout<<t1;
                                   cout<< endl;
                                   cout<<t2;
                                   cout<< endl;
                                   cout<<t3;
                                   cout<< endl;
                                   cout<<t4;
                                   cout<< endl;
                                   cout<<t5;
                                   cout<< endl;
                                   cout<<t6;
                                   cout<< endl;
                                   cout<<t7;
                                   cout<< endl;
                                   cout<<t8;
                                   cout<< endl;
                                   cout<<t9;
                                   cout<< endl;
                                   cout<<t10;
                                   cout<< endl;
                                   cout<< endl;
                                   }
                         else {
                              cin>>learn;
                         }
                              
                         cout<< "I think " <<cx.name << " is getting sleepy now.\n Bye-bye!";
                         
                         break;
                         
                    case 1:
                         cout<< "Let's just stick between 1 and 10. (10-1=9, 10-2=8 format only): \n";
                         cin>>t1;
                         cout<< endl;
                         cin>>t2;
                         cout<< endl;
                         cin>>t3;
                         cout<< endl;
                         cin>>t4;
                         cout<< endl;
                         cin>>t5;
                         cout<< endl;
                         cin>>t6;
                         cout<< endl;
                         cin>>t7;
                         cout<< endl;
                         cin>>t8;
                         cout<< endl;
                         cin>>t9;
                         cout<< endl;
                         cin>>t10;
                         cout<< endl;
                         cout<< endl;
                         
                         cout<< cx.name << " has learned all that, but sadly I don't think he can learn anymore.\n";
                         cout<< "would you like to see what he has learned? (y or n)\n";
                         cin>>learn;
                         
                         if (learn == "y"){
                                   cout<< "Show us what you know " <<cx.name;
                                   
                                   void meow();
                                   
                                   cout<<t1;
                                   cout<< endl;
                                   cout<<t2;
                                   cout<< endl;
                                   cout<<t3;
                                   cout<< endl;
                                   cout<<t4;
                                   cout<< endl;
                                   cout<<t5;
                                   cout<< endl;
                                   cout<<t6;
                                   cout<< endl;
                                   cout<<t7;
                                   cout<< endl;
                                   cout<<t8;
                                   cout<< endl;
                                   cout<<t9;
                                   cout<< endl;
                                   cout<<t10;
                                   cout<< endl;
                                   cout<< endl;
                                   }
                         else {
                              cin>>learn;
                         }
                              
                         cout<< "I think " <<cx.name << " is getting sleepy now.\n Bye-bye!";
                         
                         break;
                         
                         
                    default:
                            cout<< "Choose a formula: ";
                            cout<< endl << "addition\n";
                            cout<< "subtraction\n";
                            cout<< "multiplication\n";
                            cout<< "division\n";
                            cin>> form;
                            cin.ignore();
                            
                    }
             }
             

         
         cin.get();
         return 0;
}
__________________

Dnsgm is offline   Reply With Quote
Old 01-04-2006, 01:11 PM   #2
Baseband Member
 
Griz803's Avatar
 
Join Date: Jun 2004
Posts: 89
Default Re: C++ help

Just a couple of quick suggestions. First, break out some more functions from main, it will make it less confusing to debug and easier for the rest of us to understand. Second, I don't really understand from your post whether you're getting a compile error or a runtime. If you're seeing a runtime, then the code you're compiling from is different from that you've posted, since I can see at least 4 errors that would stop compile. Post a bit more information also, such as os and compiler next time please. Best I can tell, you need to look at braces and semi-colons first, they aren't where they oughta' be in the posted code. I hope this helps.
__________________

__________________
/*What does not kill us, makes us drink far too much caffeine*/
Griz803 is offline   Reply With Quote
Old 01-04-2006, 03:17 PM   #3
Baseband Member
 
Dnsgm's Avatar
 
Join Date: Jan 2006
Posts: 61
Default Re: C++ help

Well it works, but the problem is that when it reaches to the 'switch' command, the program gets terminated. Thats pretty much the only problem.
Dnsgm is offline   Reply With Quote
Old 01-09-2006, 08:19 PM   #4
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: C++ help

you need a char array or a string, not a single char...


char form; //needs to be char form [buffer]; or include strings and use string
int t1, t2, t3, t4, t5, t6, t7, t8, t9, t10;
char learn[10];


cout<< "Choose a formula: ";
cout<< endl << "addition\n";
cout<< "subtraction\n";
cin>> form;
cin.ignore();

switch ("addition" || "subtraction") /*char only takes the first letter from a string so it'd never make either condition true, you could try using "s" and "a"*/
__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 04:49 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0