HI, im trying to write a quiz program, i don't understand why is my first part is not right...help plz!!

# include <iostream>
# include <cmath>

using namespace std;
int main()
{

    char answer[8] = {'A', 'C', 'D', 'B', 'A', 'B', 'A', 'B'};
    char input[8];
    int correct=0, incorrect=0, position=0;
    for (int i=1; i < 9; i++)
    {
        do
            {
                cout <<" In Your answer, Please enter A B C or D "<< i <<": \n";
                cin >> input[position];
                if (input[position] !='a' ||input[position] !='b' || input[position] !='c' || input[position] !='d')
                    cout << "please enter only a, b, c, or d:\n";
            }while (input[position] != 'a' || input[position]!= 'b' || input[position] != 'c' || input[position] != 'd');
            if (input [position]= answer[position])
                correct = correct + 1;
            else
                incorrect = incorrect + 1;
                position = position + 1;
    }
    system ("pause");
    return 0;
}

Couple of things- please read the sticky threads at the top on good posting procedure. Mainly, please put your code inside code tags, like:

[code]

your code goes here

[/code]

Then, please ask a full question. What do you mean by "my first part" and "is not right"? What error message do you get, where does it point you?

Offhand, I'd say your first problem is that you're trying to take input to and evaluate the variable input as if it's an array - but you declared it as a single character. You have an array useranswer[8] - did you really mean to store the user's input there?

yeah..thx..i quickly change it..but there but my assignment still says error

yeah..thx..i quickly change it..but there but my assignment still says error

Please be more specific.

my program did say where ..all it tell me is fail
1>------ Rebuild All started: Project: assignment 3, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'assignment 3', configuration 'Debug|Win32'
1>Compiling...
1>assignment.cpp
1>Compiling manifest to resources...
1>Linking...
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>C:\Documents and Settings\100382767\Desktop\assignment 3\Debug\assignment 3.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\100382767\Desktop\assignment 3\assignment 3\Debug\BuildLog.htm"
1>assignment 3 - 2 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

It looks like you set up the project as a Windows app, but you're really making just a simple console (aka DOS) app.

Using Visual C++, when you create your project, first be sure to select "Win32 Console App" and then be sure to check the box "Make Empty Project" on the Application Wizard dialog, Application Settings tab.

thx! the program work but...when i put a b c or d it says plz enter them again

Well, you are supposed to be getting 8 answers from the user.

If you mean you're getting the input error message, that's because your logic is a bit off.

if( input[position] !='a' ||input[position] !='b' || input[position] !='c' || input[position] !='d')

will fire when the response is,anything. You need to be using AND as the Boolean operator, not OR

why and?? because is like the user only need to put a or b not a and b

i got to this part but is still didn't work...plz help

#include <iostream>
using namespace std;

void int grading(int correct);
//declares the function

int main()
{
	char answer[8] = {'a', 'c', 'd', 'b', 'a', 'b', 'a', 'b'};
	char input[8];
	int mark[8]; 
	int correct=0, incorrect=0, pos=0;

	for(int i=1; i < 9; i++) //for loop that 
	{
		do
		{
			cout <<"Enter a, b, c, or d for question" << i << ": \n";
			cin >> input[pos];
		if (input[pos] != 'a' || input[pos] != 'b' || input[pos] != 'c' || input[pos] != 'd')
			cout <<"Please enter only a, b, c, or d: \n";
		}while(input[pos] != 'a' || input[pos] != 'b' || input[pos] != 'c' || input[pos] != 'd');
		if (input[pos] = answer[pos])
		{
			correct += 1;
			mark[pos] = 1;
		}
		else
		{
			incorrect += 1;
			mark[pos] = 0;
		}
		pos += 1;
	}

	cout <<"Your total number of correctly answered questions is: " << correct << "\n";
	cout <<"Your total number of incorrectly answered questions is: " << incorrect << "\n";
	cout <<"The question that were incorrect were(1 means a correct answer, 0 means incorrect: " << mark[] << "\n";

	system ("pause");
	return 0;
}

void int grading(int correct)
{ //void function that shows if you passed the exam or not
	if (correct >= 6) //receives the amount of correct answers and calculates if you passed or not
		cout <<"You have passed the exam!\n";
	else
		cout <<"You have failed the exam.\n";
	return;
}

why and?? because is like the user only need to put a or b not a and b

Because with OR the comparison is always true. The only way the IF can be false is if input[position] is equal to all of the letters, an impossibility.

The other reason is -- you code isn't working, is it?

i got to this part but is still didn't work...plz help

With what? You didn't explain what is wrong.

i don't knows wats wrong with the do-loop

for(int i=1; i < 9; i++) //for loop that 
    {
        do
        {
            cout <<"Enter a, b, c, or d for question" << i << ": \n";
            cin >> input[pos];
        if (input[pos] != 'a' || input[pos] != 'b' || input[pos] != 'c' || input[pos] != 'd')
            cout <<"Please enter only a, b, c, or d: \n";
        }while(input[pos] != 'a' || input[pos] != 'b' || input[pos] != 'c' || input[pos] != 'd');
        if (input[pos] = answer[pos])
        {
            correct += 1;
            mark[pos] = 1;
        }
        else
        {
            incorrect += 1;
            mark[pos] = 0;
        }
        pos += 1;
    }

Please go back and read all the replies you've gotten so far. The answer to the loop problem is in there.

And, still waiting for you to put your code inside the code tags, so it will be more readable.

When you get that, then look again at line

if (input[pos] = answer[pos])

and see if you can find what's wrong there - it's a classic error we all make some time or another.

ooo..yeah..i got it...thank you sooo much guys!!!!!!!!:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.