Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracking down strange error

I'm trying to do some C++ exercises, but I'm running into a error on build, which doesn't just jump out at me. What am I missing? I'm just getting back to C++ from C# et al after having done it years ago.

[ERROR] syntax error : 'return' [/ERROR]

#include <iostream>
using namespace std;

/* Pre-compiler directives / macros */
#define isValidDrinkChoice(Choice,MaxNumDrinks) ((Choice < MaxNumDrinks) && (Choice > 0))

/* Primary Entry Point for Executable */
int main(const int & argc, char * argv[]){

    const int MaxNumDrinks = 4;
    char ** Drinks;
    Drinks = new char* [MaxNumDrinks];
    Drinks[0] = "Soda";
    Drinks[1] = "Water";
    Drinks[2] = "Coffee";
    Drinks[3] = "Tea";
    Drinks[4] = "Perrier Sparkling Water";

    int Choice = -1;
    do while(!isValidDrinkChoice(Choice, MaxNumDrinks)) {
        cout << "Please select your favorite drink\r\n\r\n" << endl;
        for (int x = 0; x < MaxNumDrinks; x++) cout << "\t" << Drinks[x] << endl;
        cin >> Choice;
        if (isValidDrinkChoice(Choice, MaxNumDrinks)) cout << "\r\n\r\n" << "You chose " << *Drinks[Choice] << endl;
    }
    return 0;
}
like image 723
bitcycle Avatar asked Aug 17 '26 11:08

bitcycle


1 Answers

I don't think there's a do while like that in C++. It's do { ... } while (expression);. Or while (expression) { ... }.

like image 142
Plynx Avatar answered Aug 19 '26 04:08

Plynx