我收到两个错误:
Error 3 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
和:
Error 4 error LNK1120: 1 unresolved externals
由于我无法让程序运行,我也不确定案例“A”是否会产生掷骰子。我不想显示案例“A”中的结果,我的直觉是 scanf
不应该在那里,但我可能是错的。
这是我的代码:
#include<stdlib.h>
#include<stdio.h>
#include <time.h>
#include <ctype.h>
#define PAUSE system("pause")
int main ()
{
int diceOne, diceTwo, diceThree;
int currentDiceSum=0, totalDiceSum=0;
char choice;
int count = 0;
srand((unsigned)time(NULL));
diceOne =rand()%6+1;
diceTwo =rand()%6+1;
diceThree =rand()%6+1;
do {
printf("\n Roll the dice, but you only get 5 rolls! You can't play forever, you know. \n");
printf("Main Menu\n");
printf("A.Roll the Dice\n");
printf("B.Display the Result of Last Roll\n");
printf("C.Quit\n");
printf("Enter your choice: ");
scanf(" %c", &choice);
choice = toupper(choice);
switch(choice) {
case 'A':
printf("Dice are rolled!'\n");
diceOne =rand()%6+1;
diceTwo =rand()%6+1;
diceThree =rand()%6+1;
count ++;
break;
case 'B':
if (count = 0) {
printf("Please roll the dice atleast once\n");
} else {
printf("Dice 1: %d\n", diceOne);
printf("Dice 2: %d\n", diceTwo);
printf("Dice 2: %d\n", diceThree);
currentDiceSum = diceOne + diceTwo + diceThree;
printf("Dice Total: %d\n", currentDiceSum);
totalDiceSum+= currentDiceSum;
}
break;
case 'C':
if (count == 5)
printf("Number of rolls: %d\n", count);
printf("Total of all dice for all rolls:%d\n",totalDiceSum);
printf("Goodbye, hope to see you again!!!\n");
PAUSE;
break;
default:
printf("Was not a valid menu choice (Please enter A,B,C\n");
break;
}
} while (choice!= 'C');
}
最佳答案
Error 3 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
这是链接器错误消息。
我认为您已经创建了一个 GUI Windows 应用程序,因为它需要 WinMain
作为入口点。
您应该在链接器设置中将子系统
更改为控制台
。
如果您使用的是 Visual Studio,请转到
项目属性
然后c\c++
然后链接器->system->子系统:CONSOLE(/SUBSYSTEM CONSOLE)
对于代码块 -
转到项目
,然后转到属性
。在构建目标
选项卡下,查看组合框类型
。对于调试
目标,将其设置为“控制台应用程序”
此外,您的程序运行良好。它没有任何其他错误,也不会崩溃。
关于c - 骰子游戏程序不会运行,但不会在掷 5 次时停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31306327/