Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Feb 14th, 2005, 11:40 PM   #1
NarrowPathPilgrim
Newbie
 
Join Date: Nov 2004
Posts: 5
Rep Power: 0 NarrowPathPilgrim is on a distinguished road
Need Help With cin Command

Hello, I have a friend who is having problems with some code that he wrote, I don't know enough to help but I thought that someone here would!
Here is the code!
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <string>
#include <windows.h>
using namespace std;
     
int main( void );

class Gun
{
     //data member declarations
     string color;
     bool draw;
     bool lock;
     int numOfBullets;
public:     
     Gun(string aColor);   //constructor
     ~Gun();                    //destructor
     
     //methods
     void drawn();
     void locked();
     int fire();
};

Gun::Gun(string aColor)
{
     numOfBullets = 10;
     draw = false;
     lock = false;
     color = aColor;
     srand((unsigned)time(0)); //seeds the time (we need the rand() function in the fire() method)
}

Gun::~Gun()
{
}

//draws the gun
void Gun::drawn()
{
     if(lock)
     {
     cout<<"gun has been locked and therefore cannot be loaded.\n";
     }   
     draw = true;
     cout<<color<<"gun has been loaded.\n" <<endl;
}

//locks the gun
void Gun::locked()
{
    if(!draw)
     {
     cout<< color << "gun has not been drawed.\n" <<endl;
     }
         
    if(draw)
     {
     lock = true;
     cout<<color<<"gun has been locked.\n" <<endl;
     }   
}

//fires the gun if locked
int Gun::fire()
{
     if(!draw)
     {
          cout<< color << "gun has not been loadedand therefore could not fire.\n" << endl;
          return 0;
     }
     int score;
     score = rand() % (10 - 0 + 1) + 0;
     if(score == 0)
          cout<<color<< " missed the target!!!\n" <<endl;
     else
          cout<< color << " scored " << score << " points!!!\n" <<endl;
     return score;
}

//the main function
int main(void)
{
     int go;
     char load;
     char lock;
     system("cls");
     cout<<"Gun Control - TS Software V1.0\n\n";
     cout<<"Welcome to gun control!\n\nToday you will learn how to aim, draw, and fire a gun at"
     " a target. Good Luck!\n";
     Sleep( 1000 );
     cout<<"\nGlad you agreed. Come on over.\n\n";
     cout<<"Ok, now we are going to use the nice, pretty old, black shotgun.\n\n";
     Gun shotgun("The old, black shot");
     cout<<"To load the shotgun type in load. You will then be told that is loaded.\n";
     cin>>load;
     cout<<"\n";
     if (load = load) {
         shotgun.drawn(); }
     cout<<"Then you would have to lock it, type in lock.\n";
     cin>>lock;
     if (lock = lock) {
         shotgun.locked(); }
     /*shotgun.draw();
     shotgun.fire();
     shotgun.loced();*/
     return 0;
}
He thought that the problem might be the cin command
Thanks in advance!
Zach Doty

Last edited by NarrowPathPilgrim; Feb 15th, 2005 at 12:12 AM. Reason: change title
NarrowPathPilgrim is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC