Thread: Comparing Arrays question

  1. #31
    Registered User
    Join Date
    Apr 2009
    Posts
    21
    while ( your_answers != 'a' && 'b' && 'c' && 'd')

    didn't work
    ........

  2. #32
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #33
    Registered User
    Join Date
    Apr 2009
    Posts
    21
    i am studying, i dont learn well by book

  4. #34
    Registered User
    Join Date
    Apr 2009
    Posts
    21
    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?

  5. #35
    Registered User
    Join Date
    Apr 2009
    Posts
    45
    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.
    Last edited by Flaug; 04-14-2009 at 06:40 PM.

  6. #36
    Registered User
    Join Date
    Apr 2009
    Posts
    45
    Quote Originally Posted by taugust7 View Post
    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?
    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'){}

  7. #37
    Registered User
    Join Date
    Apr 2009
    Posts
    45
    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:

    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;
    }
    If you can't use the "system("PAUSE")" line, then just remove it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about arrays.
    By Kelvie in forum C++ Programming
    Replies: 3
    Last Post: 09-17-2007, 05:32 AM
  2. A question about arrays
    By HAssan in forum C Programming
    Replies: 3
    Last Post: 11-08-2006, 03:09 AM
  3. Just a quick question about character arrays
    By Welshy in forum C Programming
    Replies: 3
    Last Post: 04-03-2006, 07:20 AM
  4. Question about char arrays
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 12:44 AM
  5. Question about arrays?? PLease read..
    By foofoo in forum C Programming
    Replies: 3
    Last Post: 06-24-2002, 02:40 PM