Simple C++ program - help needed

This is a discussion on Simple C++ program - help needed within the C++ Programming forums, part of the General Programming Boards category; Hey guys, this is going to seem like a jumbled mess as I'm very tired and have been trying to ...

Simple C++ program - help needed

Hey guys, this is going to seem like a jumbled mess as I'm very tired and have been trying to figure this out for awhile. So, if you get irritated easily or don't have a minute or two to spare just ignore it, heh.

I read the topics about posting, posting code, asking for help, etc. I have a legitimate need of programming help. It is for a class project in introduction to c++. We are allowed to see tutors. I have spent several hours on this program, seen a tutor at the school, and think I am at least somewhat close, but I am having some trouble puting it all together and understanding it.

I am only a math minor (music major) and this is the only programming course I'll be taking. However, it is important I actually understand how it works and I need to write programs on in class tests, among other things. So, if you actually write me some code, it would benefit me greatly if you explained it or answered questions I might have about it.

Ok, sorry for all the wording but I'm just trying to justify asking for help.

Here is the program definition:

Write a menu-driven program that will help an elementary school student learn multiplication. Use function rand to produce two positive one-digit integers. The program will ask a question such as: How much is 6 times 7?

The student then types the answer. Your program checks the student's answer and prints the various comments:

As you can see, the first half of the program is a mess. I am having trouble doing the parts where the user chooses the type of arithmetic problem and the grade level (1 digit or 2). I believe my program only works with multiplication at the moment. then, I am having trouble getting my program to ask the user a random question. I thought of typing up all the multiplication tables, etc, and using an if/else structure, but that has got to be the worst idea possible. I think maybe my problem is not entirely understanding the random number generator.

I have been reading my c++ book (absolute c++) most of the day, and working on this and trying to piece it together for many hours, but apparently I just suck at programming. sorry if what I'm asking is unclear, I'm very tired at the moment. I will post more information when I wake up.

If someone reads this and might be able to help, thanks. Otherwise, I'll add more information in the morning including what I was trying to do at various steps in the program, especially the beginning. I am willing to devote my whole weekend to getting this thing done, and am very eager to read peoples ideas and opinions.

Last edited by CornedBee; 10-06-2007 at 04:37 AM.
Reason: Broke lines in code section to preserve site layout.

I've broken the over-long lines in the code section so that they don't mess up the site layout. However, the code is still poorly formatted. Make sure you've got proper indentation, because as it is it's very hard to read. And put some spaces between operators and arguments!

Thanks for the help, especially Conspiracy! I did the data control you mentioned and I think it was a good idea. I've put the segments of my program together and corrected as many errors as I could figure out.

Sorry for the poor formatting. This is the 2nd program I've ever written on my own and I'm not sure how to make it look appealing

I decided to use 4 sections of very similar code, each with a different operator possibility, +,-,/,*.

I think this will work if I can get the program to run, but I still can't get it to run. But, now there are only a few errors.

The main problem I am having is getting the pow function to work correctly. I read that it does not function with integers but works with doubles, but my formula only works with integers because of the &#37; I used in the pow line of code not working with doubles.

It gets this error 4 times on lines 53 and 55, both of my pow code lines. I think I need the pow line of code to have that formula because otherwise, the grade entered by the user won't function correctly and my operands won't be the right number of digits.

The next error I'm getting is

Error 5 error C2679: binary '<' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)
line 72

Error 5 error C2679: binary '<' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)
line 72
I think this error is related to the pow error, and I get it 4 times.

The error is not related to the pow function problem, its because you wrote <endl; and its <<endl;
And you get it for times because you have this part:

since the grade and the leftoperand variables are type int the pow function dosent work

There is an overloaded version of std::pow() that takes a double and an int as arguments, so that function will be called. Still, even without that an implicit cast should be made, and more importantly, your version changes the calculation.