Question: C++ PROGRAM When I input 3 S P R, it was suppoesed to pop up L W T. But it showed L L L. The
C++ PROGRAM When I input 3 S P R, it was suppoesed to pop up L W T. But it showed L L L. The moveNo is not working.
#include
int main() { human h; computer c; referee r; r.compare(h,c); return 0; }
#include
//dumb computer, only choose R
char computer:: move(){ return 'R';
}
#ifndef COMPUTER_H #define COMPUTER_H class computer{ public: char move(); };
#endif // COMPUTER_H
#include
human::human(){ cin>>totalMoves;
moves=new char[totalMoves]; for(int i=0;i cin>>moves[i]; } } char human::move(){ char returnH=moves[moveNo]; return returnH; } #ifndef HUMAN_H #define HUMAN_H class human { public: char*moves; int moveNo; int totalMoves; human(); char move(); }; #endif // HUMAN_H #include void referee::compare(human h, computer c){ //char result='T'; char humanMove=h.move(); char computerMove=c.move(); int totalMoves=h.totalMoves; for(int i=0;i }cout< #ifndef REFEREE_H #define REFEREE_H #include "computer.h" #include "human.h" class referee{ public: void compare(human h, computer c); }; #endif // REFEREE_H
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
