![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 5
Rep Power: 0
![]() |
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;
}Thanks in advance! Zach Doty Last edited by NarrowPathPilgrim; Feb 15th, 2005 at 12:12 AM. Reason: change title |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|