while ( your_answers != 'a' && 'b' && 'c' && 'd')
didn't work
........
Printable View
while ( your_answers != 'a' && 'b' && 'c' && 'd')
didn't work
........
Again, that's because only the first comparison is correct. Do the same thing with each character (eg: your_answers != 'b', etc).
>> also i dont know what the crap isalpha and tolower are, this is an intro level class and im tryin to teach myself arrays and loops ya know
Ok, so how else to learn but to study? Read a few books on C++ programming, and everything will go so much easier for you.
i am studying, i dont learn well by book
Code:and the book assigned for this class doesnt have anything on validation
for (count = 0; count<=size-1; count++)
{
cin>> your_answers[count];
while (your_answers[count] != 'a' && your_answers != 'b' && your_answers != 'c' && your_answers != 'd')
{
cout<< "invalid answer";
cin>> your_answers[count];
}
}
thats were im at, now wat the heck am i doin wrong?
Sebastiani is right. What I gave you was homework- And I shouldn't have.
What do you mean by saying you can't use "(true)"? That's part of a loop. I'm using 'true' instead of a Boolean expression.
I bet if you really try hard, you can learn from a book.
As for what you are doing wrong, check out the line with the while loop in it (while (your_answers[count] != 'a' && your_.....)- You have the first evaluation right, but the second third and fourth are wrong. You forgot to add [count] to the end of 'your_answers'.
So it would look like this: while (your_answers[count] != 'a' && your_answers[count] != 'b' && your_answers[count] != 'c' && your_answers[count] != 'd'){}
This is the last bit of (whole) code I'm giving you. From now on you need to try to do this yourself. It's really not very complex stuff:
If you can't use the "system("PAUSE")" line, then just remove it.Code:#include <iostream>
using namespace std;
int main()
{
int count, correct = 0;
const int size = 20;
char your_answers[size];
char answers[size] = {'b','d','a','a','c','a','b','a','c','d','b','c','d','a','d','c','c','b','d','a'};
cout<< " Please enter the students answers. \n" ;
for (count = 0; count<=size-1; count++)
{
cin >> your_answers[count];
while(your_answers[count] != 'a' && your_answers[count] != 'b' && your_answers[count] != 'c' && your_answers[count] != 'd')
{
cout << "(" << your_answers[count] << ") Your answer is not an appropriate one. Please try again." << endl;
cin >> your_answers[count];
}
}
for (count=0; count<=size-1;count++)
{
if (answers[count] == your_answers[count])
correct += 1; //If they got this one right, then add one to 'correct'.
}
if(correct >= 15) //They got 15 or higher right
cout << "\nYou passed the test. Congratulations." << endl;
else
cout << "\nYou're a failure." << endl;
cout << "You got " << correct << " out of 20 correct." << endl;
cout << endl; //Make a new line.
for (count = 0; count<=size-1; count++)
{
cout << "Correct Answer: " << answers[count] << " | Your answer: " << your_answers[count];
if (answers[count] == your_answers[count]) //It's correct;
cout << " [CORRECT]." << endl;
else
cout << " [WRONG]." << endl;
}
system("PAUSE");
return 0;
}