gpt4 book ai didi

c++ - 追踪奇怪的错误

转载 作者:太空狗 更新时间:2023-10-29 20:01:15 26 4
gpt4 key购买 nike

我正在尝试做一些 C++ 练习,但我在构建时遇到了一个错误,这不只是突然出现在我身上。我错过了什么?在几年前完成之后,我刚刚从 C# 等人回到 C++。

[错误] 语法错误:“返回”[/错误]

#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;
}

最佳答案

我认为在 C++ 中没有像这样的do while。它是 do { ... } while (expression);。或者 while (expression) { ... }

关于c++ - 追踪奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2346462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com