Random Addition

S

snow.carriers

(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
 
J

John Harrison

(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'.

john
 
G

Greg

(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
 
K

Karl Heinz Buchegger

(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: (e-mail address removed) Web: www.gascad.com

Fuer sehr grosse Werte von 2 gilt: 2 + 2 = 5
 
K

Karl Heinz Buchegger

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.
 
K

Karl Heinz Buchegger

Karl said:
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'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top