iT邦幫忙

0

這是完整程式碼 跑出來結果說 main裡面的 return 之前少一個; [Error] expected ';' before 'return'

#include <iostream>
#include <stdlib.h>
#include <ctime>

using namespace std;

int gameStatus=0;
void opPick(int &opChoice);
void judge(int myChoice,int opChoice);

int main(){
	int myChoice,opChoice;
	do{
		cout<<"剪刀(1) 石頭(2) 布(3)";
		cin>>myChoice;
		opPick(opChoice);
		judge(myChoice,opChoice);
	}
	while(gameStatus==0)
	return 0;
}
void opPick(int &opChoice)
{
	srand(time(NULL));
	opChoice=rand()%3+1;
	switch(opChoice){
		case 1:
			cout<<"電腦出剪刀"<<endl;
			break;
		case 2:
			cout<<"電腦出石頭"<<endl;
			break;
		case 3:
			cout<<"電腦出布"<<endl;
			break;
 		}
 		return;
}
void judge(int myChoice,int opChoice)
{
			if(myChoice==1 && opChoice==3){
				cout<<"您獲勝了\a"<<endl;
				gameStatus=1;
			}
			else if(myChoice==2 && opChoice==1){
				cout<<"您獲勝了\a"<<endl;
				gameStatus=1;
			}
			else if(myChoice==3 && opChoice==2){
				cout<<"您獲勝了\a"<<endl;
				gameStatus=1;
			}
			else if(myChoice==1 && opChoice==2){
				cout<<"電腦獲勝了\a"<<endl;
				gameStatus=2;
			}
			else if(myChoice==2 && opChoice==3){
				cout<<"電腦獲勝了\a"<<endl;
				gameStatus=2;
			}
			else if(myChoice==3 && opChoice==1){
				cout<<"電腦獲勝了\a"<<endl;
				gameStatus=2;
			}
			else {
				cout<<"平手"<<endl;
							}
			return;
}
bill iT邦新手 5 級 ‧ 2021-10-13 14:44:25 檢舉
int main()底下do-while的while(gameStatus==0)最後要分號 ;
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
緯大啊緯大人
iT邦研究生 1 級 ‧ 2021-10-09 20:16:57
最佳解答

C語言?

do
{
    y = f( x );
    x--;
}
while ( x > 0 ) ;

參考
https://docs.microsoft.com/zh-tw/cpp/c-language/do-while-statement-c?view=msvc-160

while結尾要加分號吧!

0

我要發表回答

立即登入回答