Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ declaration error
#5
If you're defining playersRespond to be an integer, you need to remove the ' ' from around the 1, 2 and 3 (your if, else if and your while lines).

*Edit* What are you trying to do? Because if someone enters in a 1 or 2 you do something, otherwise you get the "Please enter 1, 2 or 3" message. You also get this message if playersRespond == 3 first time round. And why the char c bit? c has no impact, if playersRespond isn't 3 the 1st time around, you'll get an infinite loop. It makes no sense. Are you trying to do something like this?:
Code:
#include <ctime>
#include <iostream>

using namespace std;

void main() {
    srand(time(NULL));
    int guess = rand() % 99 + 1, playersRespond;
    cin >> playersRespond;
    do {
        if (playersRespond == 1) {
            // do something
        } else if (playersRespond == 2) {
            // do something else
        } else if (playersRespond == 3) {
            // response is already 3, break out of this?
            break;
        } else {
            cout << "Please type in 1, 2 or 3\n";
            cin >> playersRespond;
        }
    } while (playersRespond != 3);
}
Reply


Messages In This Thread
C++ declaration error - by sky54264 - 2009-09-15, 12:35 PM
C++ declaration error - by Tempus - 2009-09-15, 12:56 PM
C++ declaration error - by Fiel - 2009-09-15, 01:02 PM
C++ declaration error - by sky54264 - 2009-09-15, 01:04 PM
C++ declaration error - by Tempus - 2009-09-15, 02:56 PM
C++ declaration error - by Fiel - 2009-09-15, 08:13 PM
C++ declaration error - by Takebacker - 2009-09-15, 08:35 PM
C++ declaration error - by Russt - 2009-09-15, 08:52 PM
C++ declaration error - by sky54264 - 2009-09-15, 08:56 PM
C++ declaration error - by Russt - 2009-09-15, 09:07 PM
C++ declaration error - by Fiel - 2009-09-15, 09:19 PM
C++ declaration error - by Russt - 2009-09-15, 10:15 PM
C++ declaration error - by sky54264 - 2009-09-15, 11:08 PM
C++ declaration error - by Russt - 2009-09-15, 11:35 PM
C++ declaration error - by Fiel - 2009-09-16, 09:30 AM
C++ declaration error - by sky54264 - 2009-09-16, 07:23 PM
C++ declaration error - by Russt - 2009-09-18, 08:22 PM
C++ declaration error - by Fiel - 2009-09-19, 05:05 PM

Forum Jump:


Users browsing this thread: