473,465 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Random Addition

(This is personal work by the way, I took the questions from sites to
enhance my c++ at start before I go indepth)

A program will ask 10 questions in addition. If they get it wrong, they
get three tries to answer it, if they fail on all of them then it goes
to the next question. If they any correct, they get a point.

I'm moderately sure how to get started. I can see many possibilities
with this one. I'm thinking of using a random function to generate
numbers. Then make an expression if they're guess is true (boolean),
and that the next part of the loop will go. When they get another try,
and when attempt = 3, the next loop will go.

Any other ways that will make the program more efficient, use less
code? I'm trying to make it the best it can be. Any code examples of
how to start off will also help me out.

Thanks

Oct 8 '05 #1
5 1466
sn***********@gmail.com wrote:
(This is personal work by the way, I took the questions from sites to
enhance my c++ at start before I go indepth)

A program will ask 10 questions in addition. If they get it wrong, they
get three tries to answer it, if they fail on all of them then it goes
to the next question. If they any correct, they get a point.

I'm moderately sure how to get started. I can see many possibilities
with this one. I'm thinking of using a random function to generate
numbers. Then make an expression if they're guess is true (boolean),
and that the next part of the loop will go. When they get another try,
and when attempt = 3, the next loop will go.
It all seems reasonable enough, you have a loop within a loop.

Any other ways that will make the program more efficient, use less
code?
Ammount of code is not an issue, nor is efficiency. You are barking up
the wrong tree if you try to achieve either of those. The key things to
go for, the things that seperate good programmers from bad, is clarity
of code and logical design of code. Write code that is easy and natural
to understand, that solves the problem at hand but is also easily
extendible to other similar problems. Forget about efficiency and
smallness of code, those are typical newbie concerns and bogus concerns
most of the time.

I'm trying to make it the best it can be. Any code examples of how to start off will also help me out.

The issue you have not addressed is how in your random choice of
questions you will avoid asking the same question twice. That is a
problem which has an obvious but slightly messy answer, and a much
cleaner but slightly less obvious answer. Here's a hint, 'shuffle'.
Thanks


john
Oct 8 '05 #2
sn***********@gmail.com wrote:
(This is personal work by the way, I took the questions from sites to
enhance my c++ at start before I go indepth)

A program will ask 10 questions in addition. If they get it wrong, they
get three tries to answer it, if they fail on all of them then it goes
to the next question. If they any correct, they get a point.

I'm moderately sure how to get started. I can see many possibilities
with this one. I'm thinking of using a random function to generate
numbers. Then make an expression if they're guess is true (boolean),
and that the next part of the loop will go. When they get another try,
and when attempt = 3, the next loop will go.

Any other ways that will make the program more efficient, use less
code? I'm trying to make it the best it can be. Any code examples of
how to start off will also help me out.

Thanks


You should also write the program with some degree of flexibility -
since the first version of a program is rarely the last version. For
instance: making the number of wrong answers allowed or the total
number of questions easily configurable. Or to have the program adjust
the difficulty of the problems depending on the user's current score.
Or to add a timer, or..

Greg

Oct 8 '05 #3
sn***********@gmail.com wrote:

(This is personal work by the way, I took the questions from sites to
enhance my c++ at start before I go indepth)

A program will ask 10 questions in addition. If they get it wrong, they
get three tries to answer it, if they fail on all of them then it goes
to the next question. If they any correct, they get a point.

I'm moderately sure how to get started. I can see many possibilities
with this one. I'm thinking of using a random function to generate
numbers. Then make an expression if they're guess is true (boolean),
and that the next part of the loop will go. When they get another try,
and when attempt = 3, the next loop will go.

Any other ways that will make the program more efficient, use less
code? I'm trying to make it the best it can be. Any code examples of
how to start off will also help me out.

Thanks

--
Karl Heinz Buchegger, GASCAD GmbH
Teichstrasse 2
A-4595 Waldneukirchen
Tel ++43/7258/7545-0 Fax ++43/7258/7545-99
email: kb******@gascad.at Web: www.gascad.com

Fuer sehr grosse Werte von 2 gilt: 2 + 2 = 5
Oct 10 '05 #4
sn***********@gmail.com wrote:

I'm moderately sure how to get started. I can see many possibilities
with this one. I'm thinking of using a random function to generate
numbers. Then make an expression if they're guess is true (boolean),
and that the next part of the loop will go. When they get another try,
and when attempt = 3, the next loop will go.

Any other ways that will make the program more efficient, use less
code? I'm trying to make it the best it can be.


You are heading in the wrong direction.
First make it work, then sit back, look at your solution and
figure out ways how you can enhance the solution. Start with thinking
about the design and see how your current design influenced your coding.
Then think about what other designs are possible and try to implement
them.

That actually will teach you something. Asking somebody for what you
should do or shouldn't do, won't teach you much. There is just one
exception: if you neither have a solution nor have an idea how
a solution should look like, then ask. But if you have an idea, forumlate
it in a programming language. If it works, fine. There may be better ways,
shorter ways, ways that require less code, but they all have one disadvantage:
They were not 'invented' by our brain.

Making mistakes in programming which means throwing away everything
and start afresh is perfectly allowed in programming (although your boss
will not like it) and *is* a good way of learning.

--
Karl Heinz Buchegger
kb******@gascad.at
Oct 10 '05 #5
Karl Heinz Buchegger wrote:

sn***********@gmail.com wrote:

I'm moderately sure how to get started. I can see many possibilities
with this one. I'm thinking of using a random function to generate
numbers. Then make an expression if they're guess is true (boolean),
and that the next part of the loop will go. When they get another try,
and when attempt = 3, the next loop will go.

Any other ways that will make the program more efficient, use less
code? I'm trying to make it the best it can be.


You are heading in the wrong direction.
First make it work, then sit back, look at your solution and
figure out ways how you can enhance the solution. Start with thinking
about the design and see how your current design influenced your coding.
Then think about what other designs are possible and try to implement
them.

That actually will teach you something. Asking somebody for what you
should do or shouldn't do, won't teach you much. There is just one
exception: if you neither have a solution nor have an idea how
a solution should look like, then ask. But if you have an idea, forumlate
it in a programming language. If it works, fine. There may be better ways,
shorter ways, ways that require less code, but they all have one disadvantage:
They were not 'invented' by our brain.

***
Sorry. Replace 'our' with 'your'.
--
Karl Heinz Buchegger
kb******@gascad.at
Oct 10 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are...
5
by: Christopher Brandsdal | last post by:
Hi! I'm not sure, but this might be a question not right for this group. Problem: I have a sql statement that selects all rows with a sertain criteria, an display it on a page. What I need...
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
15
by: John Cassidy | last post by:
This has been driving me crazy. I've done basic C in school, but my education is mainly based on object oriented design theory where Java is our tool. For some reason, while helping a friend with a...
2
by: John | last post by:
I'm creating this program to test an elementary school kids math skills. They have five options to choose from 1 = '+' 2 = '-' 3 = '*' 4 = '/' 0 = To have the computer choose. My Problem...
12
by: Adam Hartshorne | last post by:
Hi All, I was wondering if somebody could post a few lines of code which would produce random colors, which will be used in defining different regions on a mesh. So in addition to having n...
3
by: pedestrian via DotNetMonster.com | last post by:
Let's say I declares an array of string (of size 1000), how to fill every elements of it with random characters? Dim myStrArray(999) As String ... Thanks... -- Pedestrian, Penang.
9
by: Tuxedo | last post by:
I'd like to reorganize the third, fourth, fifth and sixth, as well as any elements thereafter in an array in random order: var a = new...
5
by: Michiel Overtoom | last post by:
You wrote... Maybe this? random.randint(0, 9e16) -- "The ability of the OSS process to collect and harness
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.