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.IDK why
C++ PROGRAM When I input 3 S P R, it was suppoesed to pop up L W T. But it showed L L L.IDK why the moveNo is not working. I am asking for help, plz dont put some random things on it.
main.cpp
#include
int main() { human h; computer c; referee r; r.compare(h,c); return 0; }
computer.cpp
#include
//dumb computer, only choose R
char computer:: move(){ return 'R';
}
computer.h
#ifndef COMPUTER_H #define COMPUTER_H class computer{ public: char move(); };
#endif // COMPUTER_H
human.cpp
#include
human::human(){ cin>>totalMoves;
moves=new char[totalMoves]; for(int i=0;i cin>>moves[i]; }moveNo=0; } char human::move(){ char returnH=moves[moveNo]; moveNo=MoveNo+1; return returnH; } human.h #ifndef HUMAN_H #define HUMAN_H class human { public: char*moves; int moveNo; int totalMoves; human(); char move(); }; #endif // HUMAN_H referee.cpp #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< referee.h #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
