If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

The output of the code seems inconsistent.

The code below is for my project in my subject which is c++. The code works fine but it seems like the output is inconsistent and weird. Would you please help me think of a solution to this error? I tried to research and read books about this issue but still its not clear for me. Thank you in advance

Re: The output of the code seems inconsistent.

Please use code tags when posting code. The code you posted is practically unreadable without code tags.

The code works fine but it seems like the output is inconsistent and weird.

How can the program be "fine", but at the same time the output is "inconsistent and weird"? The program is either working correctly or it isn't working correctly.

Would you please help me think of a solution to this error?

You never mentioned what the error is. In addition, you can solve your own problems with the program by debugging the code and seeing where the problems originate. The Visual C++ compiler comes with one of the best debuggers ever made for C++ programmers. Debugging is part and parcel of learning how to write programs.

I tried to research and read books about this issue

Why are you doing all of that, when the solution is to debug your program and fix the errors?

Re: The output of the code seems inconsistent.

I don't see anything that would make it inconsistent. You need to provide more detail on exactly what the problem is.

It's a pretty inefficient design. You could have written it with a lot less code.

You don't score properly. If you enter the same number each time or two responses the same number of times, none of your if statements work. You'd be better off just coming up with a total number and rating happiness based on that.

Re: The output of the code seems inconsistent.

Would you please help me think of a solution to this error? I tried to research and read books about this issue but still its not clear for me.

I will add to what I've stated previously concerning this.

Since you seem to be a beginner in C++ programming, the way that a program is developed is as follows:

1) You create a program using an editor.
2) You use the compiler to compile the program that you wrote, and create an object file if the syntax is correct. Note the highlighted term syntax.
3) Once the object file is created, the linker then takes the object file and other external libraries, and creates a final executable.

From the above, nowhere is it stated that the final program will run correctly. In a nutshell, all you're doing when you compile and link a program successfully is that your program has correct C++ syntax, and the linker has found all functions and libraries that are used.

Your misunderstanding seems to be that if the program builds correctly, it must produce the right results when run. That's the only reason that I can see for searching books to "fix the problem", as if there is a problem with C++. Last week, there was another poster searching google for the same reason -- a program was successfully built, but didn't give the right results.

The logic of the program has absolutely nothing to do with whether the program was built correctly. As a simple example, if you were to write a program to add two numbers, and instead you mistakingly subtracted the two numbers, the program would compile and link successfully, however the results would not be correct since a mistake was made (you subtracted instead of added).

Errors such as the ones above are called logical errors, and the only way to fix logical errors is to debug your program. This means you go through the program line by line with the debugger, checking the values of your variables, and seeing where the values of the variables, path of the program, etc. goes wrong. You don't need to read books, search the Internet, or any of that to fix your errors.

Second, there is no difference in all of those q() functions you wrote, except for the text that is presented. What if there were 100 questions? Would you write 100 q() functions, all the same except for the text that is presented?

Instead, the code above:

1) Creates an array of strings, corresponding to the presented text.
2) A loop is written to go through each question.
3) A function called ShowQuestion takes as the parameter the question that I would like to ask. Note that the cout inside ShowQuestion uses the array.

Now, the logic error is still there and you need to fix it. But at the very least, the program above is simple and straightforward. To add the other questions just requires adding them to the question array.

The bottom line is that if you're writing code over and over and over again, with the only difference being a string or a couple of values here and there, then it's time to take a step back and "factor out" the common code and create functions, arrays, etc. for the parts that vary.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.