Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need 4 computers to interact, don't know means for that

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi and thanks for reading my posting! :)
I need to admit at once that I'm not a professional user of C or C++ but any comments are welcome as I'm eager to read manuals.
My task is the following:
I need to write a program that allows 4 people to sit at 4 different machines and answer questions the program asks them. While 1 person answers the other 3 should be able to see the answer and the question asked. At the same time the program should keep a record of the questions and answers. I think that these people should answer in turn and must wait until the previous person answers. So probably the program should notify the person whose turn is to answer and shouldn't allow anybody else to answer.

Again I know almost nothing about C and C++. The most valuable information that I drastically need is how to organize interaction between 4 machines: what kind of means already exist in C and C++ for that and what should I do myself. Any comments about keeping track of the answers can help as well.

Thanks a lot for your help!
 
I can only try to give you a suggestion.
I would use the CSocket (or CAsyncSocket) class of MSVC
(tutorial at: that should do it). I would create 1 server and 4 clients (so that 1 computer had to run both, and connect to localhost). The server would do nearly all the work:
The server would have 4 connected sockets:user1Socket, user2Socket, user3Socket and user4Socket. Then it would have 4 int variables, user1Score, user2Score, user3Score and user4Score.
At last (besides a int variable to control the turns like whichUserTurnIsIt) it would contain a CList or array of question classes: m_question, m_corrAns, m_wAns1, m_wAns2 etc.

The client would only contain a boolean variable myTurn and one question-object from the same CQuestion class as the server. Besides maybe some display functions that have nothing to do with the communication.

The basic idea is this: The server starts by sending one Question-object to all four users, so everyone has the question. Next it would send one boolean variables to each users: myTurn. One would be TRUE and 3 FALSE. The clients, where the myTurn variable is FALSE are allowed to view the answer (its not their turn), the 4th has to guess.
After the answer is given, the client sends a "report" back to the server: answer was TRUE or FALSE, the server increases the value userXScore and goes on sending questions to all and a TRUE-variable to userX+1Socket.

It would also be possible to send back a number or string to the server, which would send this value to the other three users, so they can see the users answer, but then you had to work with flags and send them with.

Hope this was helpful and that I did not spill your time
 
Uuups, sorry I dont think I was very clear at the end of the 2nd paragraph: what I meant was a CList or array of CQuestion class objects, which would contain the elements m_question, m_corrAns etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top