Thread: Problems with easy program

  1. #1
    Lost and confused
    Join Date
    Sep 2004
    Posts
    2

    Problems with easy program

    I'm having troubles getting this program to work. Yes i know its stupid and immature but hey at least its original. All seems to work fine until it tries to use the program play(). it outputs "Time to play :Dplay_balls". Someone please help me im new to c++. and I'm not sure if passing strings through functions is legal but couldnt find any help anywhere else. I'm on linux using KDevelop. (Any suggestions for a better linux compiler, i was using dev c++ on windows)

    Code:
    /***************************************************************************
      Name: Balls
      Copyright: Charles Ewert
      Author: Charles J. Ewert
      Date: 06/09/04 23:29
      Description: A wonderful text-based console "game" about balls.
      *Intended to get familiar with functions*
     ***************************************************************************/
    
     
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    string play (string c_balls);
    
    
    float n_balls;
    string color = "";
    string c_balls = "";
    string balls = "";
    
    
      int main()
      {
    
    
          cout << "You are in a dark room and you stumble upon some balls.\n"
          << "Play with balls?(Y/N)";
          cin >> balls;
          
          if (balls == "Y" || balls == "y")
          {
              cout << "\nGood choice.\n"
              << "How many balls did you feel?";
              cin >> n_balls;
              
              cout << "\nVery hot.\n"
              << "What color were they? (W)hite or (B)lack";
              cin >> c_balls;
              
              cout << "\n\nTime to play :D\n"
              << play(c_balls)
    	  << n_balls << " " << color << " ."
    	  << "\nCongrats! Thanks for playing skank";
          }
          else
          {
              cout << "Everyone loves balls!!\n"
              << "Go home... Game Over";
            
              return 0;
          }
      }
      string play(string c_balls)
      {
          
          if (c_balls == "B" || c_balls == "b")
          {
              color = "black";
          }
          else 
          {
              color = "white";
          }
                
          return "Even though it was dark you managed to fondle " ;
          
      }

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    98
    I try to run it , it's work ok.

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    string play (string c_balls);
    
    
    float n_balls;
    string color = "";
    string c_balls = "";
    string balls = "";
    
    
      int main()
      {
    
    
          cout << "You are in a dark room and you stumble upon some balls.\n"
          << "Play with balls?(Y/N)";
          cin >> balls;
          
          if (balls == "Y" || balls == "y")
          {
              cout << "\nGood choice.\n"
              << "How many balls did you feel?";
              cin >> n_balls;
              
              cout << "\nVery hot.\n"
              << "What color were they? (W)hite or (B)lack";
              cin >> c_balls;
              
              cout << "\n\nTime to play :D\n"
              << play(c_balls)
        << n_balls << " " << color << " ."
        << "\nCongrats! Thanks for playing skank";
          }
          else
          {
              cout << "Everyone loves balls!!\n"
              << "Go home... Game Over";
            
              return 0;
          }
            cin.ignore();                   //add  three statements in here.
            cin.get();
            return 0;
      }
      
      string play(string c_balls)
      {
          
          if (c_balls == "B" || c_balls == "b")
          {
              color = "black";
          }
          else 
          {
              color = "white";
          }
                
          return "Even though it was dark you managed to fondle " ;
          
      }

  3. #3
    Lost and confused
    Join Date
    Sep 2004
    Posts
    2
    After adding your code it still does the same thing. Only thing i can think of is my compiler. I will try to get a new one and see if it works.

    Edit: found out how to use g++ (linux noob too) and all works fine. C++ yay
    Last edited by chuckster; 09-09-2004 at 02:40 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with DLLEXPORT while updating a program
    By pirata in forum C++ Programming
    Replies: 3
    Last Post: 09-05-2008, 01:00 PM
  2. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Help with very easy program
    By plshelpme in forum C Programming
    Replies: 9
    Last Post: 11-02-2005, 12:11 PM
  5. GPA Program Problems
    By Clint in forum C Programming
    Replies: 3
    Last Post: 04-28-2005, 10:45 AM