473,503 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ program

1 New Member
Write a program that will generate, but not display, a three-digit "target" number that has three distinct digits. Then, inputs a maximum of eight user guesses and, for each guess, outputs the number of "hits" and "matches" in the guess. The program stops when the user guesses the correct number or runs out of guesses.

For example, if the target number is 427, the guess 207 has one hit (7) and one match (2), whereas the guess 749 has two matches (4 and 7), and the guess 327 has two hits (2 and 7).


The Program
At a minimum, your program will need to contain and make use of the two user-defined functions, placed in the "game" library, as follows:
A function that generates and returns a new number matching the task specifications. Its prototype is
int generateNewNumber();
A function that takes as input two numbers one and two, and outputs, through reference parameters hits and matches, the number of hits and matches between the two numbers. Its prototype is
void getHitsAndMatches( int one, int two, int & hits, int & matches );

Examples:
Note: user entered values are shown in bold.

Example 1:
After every trial the program displays the number of hits and matches.
Enter your guess (it must be between 100 and 999): 345
You got 1 hits and 2 matches
Enter your guess (it must be between 100 and 999): 354
You got 3 hits and 0 matches
It took you 2 tries to guess 354 correctly.

Example 2:
The program should perform some input checking. Minimally, it should check if the input number is in the range.
Enter your guess (it must be between 100 and 999): 45
Enter your guess (it must be between 100 and 999): 8888
Enter your guess (it must be between 100 and 999): 677
You got 1 hits and 0 matches
Enter your guess (it must be between 100 and 999): 247
You got 1 hits and 0 matches
Enter your guess (it must be between 100 and 999): 137
You got 2 hits and 0 matches
Enter your guess (it must be between 100 and 999): 837
You got 1 hits and 1 matches
Enter your guess (it must be between 100 and 999): 139
You got 1 hits and 0 matches
Enter your guess (it must be between 100 and 999): 187
You got 3 hits and 0 matches
It took you 6 tries to guess 187 correctly.

Example 3:
If the user didn't guess the number then the program displays a message that includes the "target".
.................................................. ....
You got 0 hits and 0 matches
Enter your guess (it must be between 100 and 999): 333
You got 1 hits and 0 matches
The number you didn't guess correctly was 361

Important Notes:
The Files subdirectory for this assignment contains skeleton files for the library files,
game.h and game.cpp
the "RandomInt" library files, RandomInt.h and RandomInt.cpp
as well as the application file, guess.cpp.
In the Files subdirectory for this assignment, there is a Makefile that you can use to build the final executable program. If your program does not contain any syntax errors and you have not changed the names of any of the files, make will build the executable file guess.
Caution: after you copy the Makefile, you may need to ensure that target command lines begin with a TAB space rather than several individual spaces.
The Makefile will be supplied automatically for you during the marking procedure. It is essential that you name your program files as specified.
Compile often. It is better to make small incremental changes and then compile, then it is to add large amounts of code and then try to compile.
You should add comments to your code.
Test your program. (In particular, be sure to test it on turing before you submit it.) Does it behave as expected when valid data are entered?
During the marking procedure, your program may be run with a data set that contains different values than those in the example data set
Sep 4 '06 #1
1 2638
Banfa
9,065 Recognized Expert Moderator Expert
And you are expecting us to do this for you?

Write the program yourself, then we will help you iron the bugs out of your code.
Sep 4 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
14144
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
22
3574
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
6075
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
11
2580
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
1
3248
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
9
4519
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
7
13247
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and...
2
19320
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
0
13290
amitpatel66
by: amitpatel66 | last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations: Concurrent programs can be executed...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.