0

<< This thread is split off from a discussion that originated here: [thread]62976[/thread] >>

Here;s something you can work on. It may not be exactly what you need but its a basis at least. Also, why do you need to check if the second number of the division is zero, from the second you say it will accept values from 1-20?? Anyway, I put the check in the program as well if u need it for later on.. Hope it helps, byee

#include <iostream>
#include <ctime>
 
using namespace std;
 
int DoMenu();
void addition(int random1, int random2);
void subtraction(int random1, int random2);
void multiplication(int random1, int random2);
void division(int random1, int random2);
 
int main()
{  
    int random1, random2;
    srand(time(0));
 
    int choice;
 
    do
    {
        random1 = 1+(rand()%20); // from 1-20
        random2 = 1+(rand()%20); // from 1-20
 
        choice = DoMenu();
 
        switch (choice)
        {
            case 0: cout << endl;                     break;
            case 1: addition(random1,random2);         break;
            case 2: subtraction(random1,random2);     break;
            case 3: multiplication(random1,random2); break;
            case 4: 
                {
                    if (random2 == 0)
                        cout << "Error: Division by zero, cannot proceed\n";
                    else
                        division(random1,random2);
                } break;
            default : cout << "Error in input\n\n"; break;
        }
 
    } while (choice != 0);
 
    return 0; 
}
 
int DoMenu()
{
    int MenuChoice;
        cout << "(1)Addition\n";
        cout << "(2)Subtraction\n";
        cout << "(3)Multiplication\n";
        cout << "(4)Division\n";
        cout << "(0)Quit\n";
        cout << "-----------------\n";
        cout << "Choice: ";
    cin >> MenuChoice;
    return MenuChoice;
}
 
void addition(int random1, int random2)
{
    int answer;
 
    cout << "\n" << random1 << " + " << random2 << " = ";
    cin >> answer;
 
    if (answer == (random1+random2))
        cout << "Congratulations\n\n";
    else
        cout << "Incorrect\n\n";
}
 
void subtraction(int random1, int random2)
{
    int answer;
 
    cout << "\n" << random1 << " - " << random2 << " = ";
    cin >> answer;
 
    if (answer == (random1-random2))
        cout << "Congratulations\n\n";
    else
        cout << "Incorrect\n\n";
}
 
void multiplication(int random1, int random2)
{
    int answer;
 
    cout << "\n" << random1 << " * " << random2 << " = ";
    cin >> answer;
 
    if (answer == (random1*random2))
        cout << "Congratulations\n\n";
    else
        cout << "Incorrect\n\n";
}
 
void division(int random1, int random2)
{
    int answer;
 
    cout << "\n" << random1 << " / " << random2 << " = ";
    cin >> answer;
 
    if (answer == (random1/random2))
        cout << "Congratulations\n\n";
    else
        cout << "Incorrect\n\n";
}
7
Contributors
13
Replies
14
Views
10 Years
Discussion Span
Last Post by jbennet
Featured Replies
  • 1
    WaltP 2,905   10 Years Ago

    [QUOTE=confused!;282545]Is there possibly a happy medium? [/quote] Yes, and I explained that to [B]may4life[/B]. He seemed to understand, then ignored me. As [B]JoeProgrammer[/B] suggests [quote]So if they're only stuck on one idea or concept, why not help them specifically with that part, instead of showing them the entire program? If … Read More

0

*sigh* Hey there May4life I know what I am saying is not officially according to the Daniweb rules but you are spoiling the newbies.

Just handing them readymade solutions will stunt their development in these things, they would never think of doing things their own, will always expect an easy answer, and much more.

Can't you atleast let these people have a shot of it....

We have already been there with you (I suppose a PM was sent to you) but still you must think that the thing "hope it helped" isn't helping them but just harming them in an irreversible way.

Hope you understand the point I am trying to prove..

0

*sigh* Hey there May4life I know what I am saying is not officially according to the Daniweb rules but you are spoiling the newbies.

Just handing them readymade solutions will stunt their development in these things, they would never think of doing things their own, will always expect an easy answer, and much more.

Hey there s.o.s,

I totally understand your point of view but as you said, i'm not doing anything against the rules here. I respect the rules and try as much as I can to stay within the limits of what i do.
As for "spoiling" newbies, I too am quite new at this stuff (i've only been learning C++ for nearly 3 months now) and I got as far as I have by studying other people's examples and solutions, in the same way that I am helping others in here now.

Can't you atleast let these people have a shot of it....

We have already been there with you (I suppose a PM was sent to you) but still you must think that the thing "hope it helped" isn't helping them but just harming them in an irreversible way.

Hope you understand the point I am trying to prove..

You're right, I have been sent a PM about the same "problem" ;)
As I also mentioned in that, there are many ways to solve a problem, I just give one which i believe is best. Now, if the person that gets this code decides to simply take it, copy it and give it in as his/her own work without at least making the effort of understanding it, that's their problem in the sense that they will most likely fail their written exam or get caught in the act (maybe someone else in the same forum is taking the same class and decides to copy the code). I have absolutely nothing to lose; instead I like not only taking these programs and solving them as a test to myself, but I also like making other people happy and calming them down after the agonizing hours they've already spent trying to solve their problem.
I just want to make it clear that I am not trying to give people easy solutions to their homework, I am not trying to get anyone in trouble.. I just give them a method for easier studying (if they want it). I just want everyone to know the ways I (personally as myself) would face and handle certain programming problems. I also mention this in the PMs I get from people that need help with their programs, not only in this forum but all the others I am signed up with. I have no problem with other programmers saying stuff like "I would use this instead of what you use", or "Your code isnt as efficient as mine". That's how we learn and also understand new concepts.
Making people happy is very easy to do, keeping everyone happy is the hardest! I am really sorry if what I'm doing affects you in a bad way, but to tell u the truth, this is the reason I sign up to forums.
Up to now its been great and honestly this is the best forum so far, by far!! I've made loads of friends and get a lot of practice and knowledge from other people. And as far as my programming skills are concerned, I have found that these forums are the best and fastest way to learn!

0

*sigh*

Maybe time will teach you or tell you the reason why the professionals are not in favor of posting entire solutions.

And just one more thing which I picked from the google groups:
"Anyone can write a program, but to help somone in understanding a program is what makes a real programmer"

Try to walk through the newbies and then you will realize how difficult it is.

Anyways I havent got anything more to say. Glad you replied.

0

As for "spoiling" newbies, I too am quite new at this stuff (i've only been learning C++ for nearly 3 months now) and I got as far as I have by studying other people's examples and solutions, in the same way that I am helping others in here now.

Hmm, so if you're a newbie, you hand them some code that may not necessarily be correct or using proper coding practices, and say "here, learn from this," what do you think that is going to teach them, even if they do study and try to learn from it?

As I also mentioned in that, there are many ways to solve a problem, I just give one which i believe is best. Now, if the person that gets this code decides to simply take it, copy it and give it in as his/her own work without at least making the effort of understanding it, that's their problem in the sense that they will most likely fail their written exam or get caught in the act. I have absolutely nothing to lose;

Yes, you have nothing to lose, but what about the newbies? Do you think if we handed code to every single person that was having trouble, they would study it? If we actually try to explain things to them and not simply say "learn my example", they will perhaps learn how the code works, and then when a test or exam comes, they will do well!

instead I like not only taking these programs and solving them as a test to myself, but I also like making other people happy and calming them down after the agonizing hours they've already spent trying to solve their problem.

Which do you think will help them remember better: if they've spent agnoizing hours on it until someone finally explains it and it makes sense, or if they've just been dumped a pile of code and said "here, have fun"?

I, for one when learning, almost never forget the stupid mistakes that I make at first if I spend a while trying to solve them. When programming in C++ now, it's very rare that I mistakenly forget to put a semicolon at the end of my sentance.

I just want to make it clear that I am not trying to give people easy solutions to their homework, I am not trying to get anyone in trouble.. I just give them a method for easier studying (if they want it).

Programming boils down to 2 things: experience and discipline. These 2 can only be gained by actually doing the work, and not studying someone else's code. By giving them complete, working examples, you keep them from doing these things. For example, if you had never coded before, but had seen and studied C++ for several years, would you recognize compiler errors?

Probably not. They can be somewhat cryptic and confusing, and it takes experience to know what each message means and what is wrong with your code. Also, coding experience helps you prevent errors from happening, as you get into a routine of placing a semicolon at the end of each statement, etc, etc.

So, although someone *might* actually try to learn from the code you give them, why not actually explain what it does? Coding books are not made entirely out of code; they have text to explain what the code does. And although you say "the student can do what he wants with the code," the disappointing fact is that it's almost like placing a little kid next to a cookie jar and saying "don't eat the cookies inside". Take away the temptation, and the student won't do it. You may actually be saving them from failing the class by not handing them their assignments.

I'm with Mr. ~s.o.s~ on this one.

0

I'm with Mr. ~s.o.s~ on this one.

Interesting. That's at least 3 that think your analysis does not help new programmers. What is it you understand that seasoned professionals (at least one of which has experience as a teacher) are missing? Especially being new yourself?

0

Hmm, so if you're a newbie, you hand them some code that may not necessarily be correct or using proper coding practices, and say "here, learn from this," what do you think that is going to teach them, even if they do study and try to learn from it?

I am not a newbie, i've been programming for years. I've recently got into C++! That's a big difference. I know my code is correct and I aways post it without warnings or errors.

Yes, you have nothing to lose, but what about the newbies? Do you think if we handed code to every single person that was having trouble, they would study it? If we actually try to explain things to them and not simply say "learn my example", they will perhaps learn how the code works, and then when a test or exam comes, they will do well!
Which do you think will help them remember better: if they've spent agnoizing hours on it until someone finally explains it and it makes sense, or if they've just been dumped a pile of code and said "here, have fun"?

Lets get this clear, I DO agree with you all. The best way to remember and learn something is by yourself and spending a lot of time doing it. Having a program to look upon is not a problem. For example, if the person doesn't understand switch statements and i have one in the code i wrote, the responsible thing to do is go look it up, learn how it works and compare it to the code. I mention these things in PMs i get to everyone i speak to.
The general idea i'm trying to get across is that i am giving out my idea of how I would solve that problem (and also giving the code of how to do it). I urge people to look at my code (to understand how i thought of overcoming the problem) and then give it a go with their own ideas. A lot of people here are vert smart, they are just confused or stuck on an idea or concept. By seeing how I overcame that specific point in the program clears these thoughts out and lets them continue onwards from there. That's what I mean when i say they have spent hours trying to solve their problem.

So, although someone *might* actually try to learn from the code you give them, why not actually explain what it does? Coding books are not made entirely out of code; they have text to explain what the code does. And although you say "the student can do what he wants with the code," the disappointing fact is that it's almost like placing a little kid next to a cookie jar and saying "don't eat the cookies inside". Take away the temptation, and the student won't do it. You may actually be saving them from failing the class by not handing them their assignments.

What makes you think if someone doesnt give them some help with the code, everyone WILL learn by themselves? If someone is in a really hopeless state and cant do anything about it, giving them code will actually boost them into the learning process. For example, i wanted to make a 3D game in openGL but couldn't find code anywhere! It was my final year project at uni so i didnt have time to learn openGL from scratch. I had to find some sort of code, learn it fast and continue from there. I did finally find some and finished on time! That was the best thing that ever happend to me

What is it you understand that seasoned professionals (at least one of which has experience as a teacher) are missing? Especially being new yourself?

I never said i was smarter than anyone else or that i know anything more than anyone in here. As far as the being new yourself, i covered that at the beginning of this message. Being a teacher, you too should know that a lot of teachers teaching the same subject have different methods. Same syllabus, different ways of communicating. Imagine if you never gave any code in the class, just teached theory and told the students to go out and google "linked lists".. How many would come back knowing how they work with a coded example of their own? 1? 2 the most? Only the ones who really really really care. By giving them a working example of one though, gives the basis and makes things a whole lot easier.

0

Do you think if we handed code to every single person that was having trouble, they would study it?

Which do you think will help them remember better: if they've spent agnoizing hours on it until someone finally explains it and it makes sense, or if they've just been dumped a pile of code and said "here, have fun"?

Programming boils down to 2 things: experience and discipline.

Also, coding experience helps you prevent errors from happening, as you get into a routine of placing a semicolon at the end of each statement, etc, etc.

Coding books are not made entirely out of code; they have text to explain what the code does.

Ah..what a thing to say...couldn't have put it better. Kudos to you ;)

Being a teacher, you too should know that a lot of teachers teaching the same subject have different methods. Same syllabus, different ways of communicating. Imagine if you never gave any code in the class, just teached theory and told the students to go out and google "linked lists"..

Have you ever seen Mr. WaltP's replies or the answers he gives to people? Probably not. Because if you had, you would have know that he always gives the links and the algorithm which can be used to solve the problem, guides them step by step and helps in the way which helps in developing their programming sense.

Dont you ever wonder why the people at Google Groups( one of the finest C++ message board on earth) never hand out complete solutions to people unless they see an atttempt ? There must be something that you are missing and they have understood quite well.

Try to guide a newbie through his question and you will know how difficult it is. Finallly I will go out to be euphemistic and say that *you are killing the programming spirit*.

Thank you.

0

It's fine to write code for people, as long as you charge a good price. I see it as a win win situation. Keep doing your stuff may4life, it's good experience for any newbie like yourself.

0

Is there possibly a happy medium?

I am a "newbie" - I am as new as they come, taking my very first ever programming class which happens to focus on C++. There were no prerequisites for this class but the teacher I have seems to assume that everyone in the class has had some experience with programming. In many cases, he is right, but there are some of us that have had no experience at all.

I have posted for help a couple of times and have gotten some help, or have gotten absolutely no response and sometimes I just get personal messages telling me to put my code in tags. It was may4life that has helped me the most. First of all, may4life explained to me what it meant to put my code in tags, since I am a newbie who truly doesn't know anything about programming for the life of me couldn't figure out what that even meant. Second of all, I don't think it's fair to assume that all the students out there just post their problems wanting someone else to do the work. I, myself, have spent countless hours reading my assignments, going through my class notes, I even bought a book at Barnes and Noble called "Teach yourself C++ in 24 hours", still I can spend 10-12 hours in front of the computer on a Sunday afternoon and not be able to figure out where to begin with a program. I can write out in English what I want the program to do, but sometimes can't come up with any code to get myself started. may4life has helped me out, given me code, which I then studied and played with to figure out what the purpose of each line of the code was for.

To me, it's kind of like learning a foreign language, sometimes you can't come up with words on your own, but you can read it and translate it in your head, and this helps you learn the language. That is exactly where I am with this C++ programming. So, though I understand that a small percentage of people could be posting just to get out of doing their homework, please don't assume that all of us are doing that. I, myself, wouldn't dream of turning in someone else's work without understanding each piece of it and modifying it to make it my own.

This website is fantastic and I appreciate the fact that you all are out there to help, but please understand that some of us are so new at this that we need a push, and without help we don't even know where to start with the code.

Just wanted to let you know where a true "newbie" is coming from.

Thanks,
confused!

0

The concept of actually writing code is really a waste of time, for newbies like yourself. It's amazing how many people worry about the syntax.

All programs should begin as flow charts. I'm sure you've come across these in baby school.

Once you have grasped the notion that all programs are essentially just flow charts, then you can move onto the next stage. Converting the flow charts into code.


Simple.

And just for the record I was being sacastic in the sense that may4life was doing you a favour by writing your code for you. He shouldn't have, and he's a fool for doing so. He he.

You learn by your mistakes. That's how you become great.

Votes + Comments
Very clearly written. -joeprogrammer
0

I've recently got into C++! That's a big difference. I know my code is correct and I aways post it without warnings or errors.

Code is not necessarily correct simply by having the compiler not give out errors/warnings. For example, Visual C++ does not complain if you use void main() . Does that mean it's correct? Bugs can also be present, which may not show themselves at first.

For example, if the person doesn't understand switch statements and i have one in the code i wrote, the responsible thing to do is go look it up, learn how it works and compare it to the code.

And the responsible thing to do when you're helping a newbie is to actually look it up if necessary, and explain what the code does.

The general idea i'm trying to get across is that i am giving out my idea of how I would solve that problem (and also giving the code of how to do it). I urge people to look at my code (to understand how i thought of overcoming the problem) and then give it a go with their own ideas. A lot of people here are vert smart, they are just confused or stuck on an idea or concept.

So if they're only stuck on one idea or concept, why not help them specifically with that part, instead of showing them the entire program? If they are capable of writing *most* of the program, let them do that. Let them get experience with that part. If they are truly stuck on a part, explain to them how to do it AND give them a code example. That's the best way of teaching someone.

By seeing how I overcame that specific point in the program clears these thoughts out and lets them continue onwards from there.

No, by giving them the entire code, you are keeping them from progressing. When they have to repeat the procedure or something similar, they will almost certainly remember how to do it if they solved it (or at least most of it) by themselves. The chances are much lower they will remember if someone simply handed them the code to complete the previous assignment.

What makes you think if someone doesnt give them some help with the code, everyone WILL learn by themselves?

Helping someone with code does not mean that you have to complete their assignment for them. In fact, explanation and small examples can often be far more helpful than dumping code at them.

Also, we that do explain to the newbies how code works, to the best of our ability, put a lot of time and effort into our posts. It's not easy. Are you saying that your method is better than ours? Obviously you must spend some time coding, too, but it's a lot harder and more time-consuming then it seems to give a good explanation on how a particular function/code snippet works.

Being a teacher, you too should know that a lot of teachers teaching the same subject have different methods. Same syllabus, different ways of communicating. Imagine if you never gave any code in the class, just teached theory and told the students to go out and google "linked lists"..

Do you realize what you are saying here? By giving people complete code for their assignments, you are expecting them to use Google! If, when you explained linked lists, you gave a code example, the student should neither have to use Google for learning how the code works or finding a good coding example. That is the professional, and preferred, way of helping people.

How many would come back knowing how they work with a coded example of their own? 1? 2 the most? Only the ones who really really really care.

Exactly. Only people who really care will write their own code example if you give them the complete code for an assignment. If they hand in the code that you gave them, it's not their own. Period.

Is there possibly a happy medium?

Obviously, yes. I have no problem giving an example of a concept I'm trying to explain, which the newbie can modify and use in their project. If they have trouble applying it to use in their project, they can post what they tried, and I'm happy to tell them what's wrong with their code.

I have posted for help a couple of times and have gotten some help, or have gotten absolutely no response and sometimes I just get personal messages telling me to put my code in tags. It was may4life that has helped me the most. First of all, may4life explained to me what it meant to put my code in tags, since I am a newbie who truly doesn't know anything about programming for the life of me couldn't figure out what that even meant.

Hmm... you mean this post wasn't clear as day? Many newbies can figure out how to use them simply by finding the sticky at the top of the forum or the watermark in the Quick Reply Box. Even if my example didn't work, surely you could have clicked on the link I referred you to.

1

Is there possibly a happy medium?

Yes, and I explained that to may4life. He seemed to understand, then ignored me.

As JoeProgrammer suggests

So if they're only stuck on one idea or concept, why not help them specifically with that part, instead of showing them the entire program? If they are capable of writing *most* of the program, let them do that. Let them get experience with that part. If they are truly stuck on a part, explain to them how to do it AND give them a code example. That's the best way of teaching someone.

Key word -- example! I go as far as to say that example does not even have to solve their problem, but shows a technique that they can use to solve it themselves.

may4life's argument is if you give them a working solution, the people that really want to learn will. I completely agree. It's the other 50-60% of them I don't want passing on someone else's work. There are enough hacks in the industry already. We don't need more graduates that barely know what they are doing because rather than figure it out, someone else does their work for them. It's these people that should not be given code. And if you really want to learn, they don't want it written for them. Therefore, the common denominator -- don't give working solutions. Give examples that explain the idea and let them solve it themselves.

I am a "newbie" - I am as new as they come, taking my very first ever programming class which happens to focus on C++. There were no prerequisites for this class but the teacher I have seems to assume that everyone in the class has had some experience with programming. In many cases, he is right, but there are some of us that have had no experience at all.

Sorry about that. Is this a reason you should be given a solution -- because your instructor sucks? Sounds like a lame excuse to me.

I honestly understand your dilema. There are a lot of bad teachers out there, and many of them are teaching bad coding practices. Unfortunately, it's the school that has to do something about that. Still, handing you the solution does not help you. Reading the book and asking questions will. That's what we're here for. We'll help clear up the crap your instructor hands you. But if you are given the solution, what incentive is there to learn -- you can still pass. "Hey guys, just go over to Daniweb. They'll do your homework for you so at least you can pass!." Get real!

I have posted for help a couple of times and have gotten some help, or have gotten absolutely no response and sometimes I just get personal messages telling me to put my code in tags.

When did you read Rules link, or the links at the top of the C/C++ forum? No wonder you didn't know. You didn't bother to get the information you needed to post accurately. Not our problem. Sorry. The Rules/FAQ was written for a reason. Just like the School Handbook you probably didn't read either (which I didn't read, so I'm just as guilty). But the excuse "I didn't know" doesn't hold water. You could have found out quite easily -- by reading the Rules.

It was may4life that has helped me the most. First of all, may4life explained to me what it meant to put my code in tags, since I am a newbie who truly doesn't know anything about programming for the life of me couldn't figure out what that even meant.

And so does the post Please use BB Code and Inlinecode tags at the top of the forum. It's right there in blue and white.

Second of all, I don't think it's fair to assume that all the students out there just post their problems wanting someone else to do the work.

I'm not assuming that at all. I'm assuming all students are human -- and as such, the majority -- if handed the answer -- will use it. There are many that won't. Maybe you're one. But how the heck are we supposed to tell. We don't have an application where you raise your right hand on a Bible and repeat "I will not use code that is written for me. I will write it myself."

I, myself, have spent countless hours reading my assignments, going through my class notes, I even bought a book at Barnes and Noble called "Teach yourself C++ in 24 hours", still I can spend 10-12 hours in front of the computer on a Sunday afternoon and not be able to figure out where to begin with a program. I can write out in English what I want the program to do, but sometimes can't come up with any code to get myself started. may4life has helped me out, given me code, which I then studied and played with to figure out what the purpose of each line of the code was for.

Very commendable. But if you were not given the solution, but code examples instead, are you saying you could not have learned it? And can you guarantee most others do what you do? So we should do the homework and hope that they don't want the easy A...

So, though I understand that a small percentage of people could be posting just to get out of doing their homework, please don't assume that all of us are doing that. I, myself, wouldn't dream of turning in someone else's work without understanding each piece of it and modifying it to make it my own.

I'm not making that assumption. I am assuming that the slugs exist. And I know for a fact they will use a solution if given to them. And I also know for a fact that for someone like you, a solution is not necessary. A code snippet showing a way to do something that you can translate yourself into working code is going to be a better learning experience.

This website is fantastic and I appreciate the fact that you all are out there to help, but please understand that some of us are so new at this that we need a push, and without help we don't even know where to start with the code.

Just wanted to let you know where a true "newbie" is coming from.

I agree. A push. But stay on your own two feet, you should not be carried. That's all a working solution is. Code snippet -- a push. Working code -- lazy man's out.

I appreciate your position and "where you'tre coming from." We've all been there. At the same time, can you understand what we're trying to say? Solutions do not help in the long run. Tips and techniques do.

To paraphrase the fish thing:
Give a student the code, they pass the course. Teach them to code, they have a carreer.

Votes + Comments
Ahh... couldn't have said it better. -joeprogrammer
0

i agree. I will help newbies with coding ONLY if they:

have done either an alpha piece of code and have a clear idea of what they want, but are just having trouble doing it

Dont know where to start but are prepared to do the work themselves if we point them in the right direction with some psuedocode or something

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.