[問題] 主程式一呼叫標頭檔就出錯
遇到的問題: (題意請描述清楚)
我寫了一個主程式和一個標頭檔tenfive.h,若主程式沒呼叫標頭檔就能順利編譯,但
主程式只要加了#include "tenfive.h"就出現錯誤了。
希望得到的正確結果:
目前只要求能順利編譯…
程式跑出來的錯誤結果:
錯誤訊息如下:
11 C:\Dev-Cpp\work\hh6.cpp new types may not be defined in a return
type
11 C:\Dev-Cpp\work\hh6.cpp extraneous `int' ignored
11 C:\Dev-Cpp\work\hh6.cpp `main' must return `int'
開發平台: (例: VC++ or gcc/g++ or Dev-C++, Windows or Linux)
Dev C++
有問題的code: (請善用置底文標色功能)
主程式
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include "tenfive.h"
int main()
{
enum Continue { Y, N };
Continue gameConti;
gameConti = Y;
while ( gameConti == Y )
{
cout << "Try again?";
cout << "Enter \"y\" to try again, enter \"n\" to exit." << endl;
int Conti;
cin >> Conti;
switch ( gameConti )
{
case 'Y':
case 'y':
gameConti = Y;
cout << "Play again!" << endl;
case 'N':
case 'n':
cout << "Exit." << endl;
gameConti = N;
default:
gameConti = Y;
cout << "Play again!" << endl;
}
}
return 0;
}
標頭檔
//tenfive.cpp
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include <string>
using std::string;
#include <cstdlib>
using std::rand;
using std::srand;
class tenfive
{
public:
void DealCard1()
{
point1 = 8 + rand()%3;
suit1 = rand()%4;
}
void DealCard2()
{
card2 = 1 + rand()%54;
NoofCard += 1;
point2 = 1 + card2%13;
suit2 = card2 / 13;
switch ( suit2 )
{
case 0:
cout << "You get A" << point2 << "." << endl;
case 1:
cout << "You get v" << point2 << "." << endl;
case 2:
cout << "You get []" << point2 << "." << endl;
case 3:
cout << "You get <^>" << point2 << "." << endl;
case 4:
cout << "You get joker." << endl;
}
}
float pointSum()
{
if ( point2 <= 13 && point2 >= 11 )
allpoint += 0.5;
else if ( suit2 == 4 )
{
if ( (allpoint + 10) > 10.5 )
allpoint += 0.5;
else
allpoint += 10;
}
else
allpoint += point2;
cout << "Now your point is " << allpoint << endl;
}
void DealOrEnd()
{
if ( allpoint >= 10.5 )
WinOrLose();
else if ( NoofCard >= 5 )
cout << "You win! (You get 5 cards.)" << endl;
else
DealAgain();
}
void WinOrLose()
{
cout << " The banker's point is " << point1;
if ( allpoint > 10.5 || allpoint <= point1 )
cout << "You lose!" << endl;
else if ( allpoint == 10.5 || allpoint > point1 )
cout << "You win!" << endl;
}
void DealAgain()
{
int deal = 0;
cout << "Enter \"1\" to deal again, otherwise start the gamble." << endl;
cin >> deal;
if ( deal == 1 )
{
DealCard2();
pointSum();
}
else
WinOrLose();
}
void settozero()
{
NoofCard = 0;
allpoint = 0;
}
private:
int card2;
int NoofCard;
int point1;
float point2;
float allpoint;
int suit1;
int suit2;
}
補充說明:
遇到 `main' must return `int' 這個錯誤訊息該如何除錯,有請版友指導,謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.206.28
推
03/23 19:10, , 1F
03/23 19:10, 1F
→
03/23 19:10, , 2F
03/23 19:10, 2F
→
03/23 19:10, , 3F
03/23 19:10, 3F
→
03/23 19:12, , 4F
03/23 19:12, 4F
推
03/23 19:12, , 5F
03/23 19:12, 5F
→
03/23 19:13, , 6F
03/23 19:13, 6F
推
03/23 19:14, , 7F
03/23 19:14, 7F
→
03/23 19:14, , 8F
03/23 19:14, 8F
→
03/23 19:15, , 9F
03/23 19:15, 9F
→
03/23 19:17, , 10F
03/23 19:17, 10F
推
03/23 19:38, , 11F
03/23 19:38, 11F
※ 編輯: graduateme 來自: 140.115.206.28 (03/23 20:50)
推
03/23 23:11, , 12F
03/23 23:11, 12F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章