【发布时间】:2015-07-09 00:51:02
【问题描述】:
我收到两个错误:
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');
}
【问题讨论】:
-
请正确缩进你的代码;它不可读。该错误看起来好像缺少某些库。我不知道windows,但是:难道你正在编译一个windows-appication而不是一个控制台应用程序?
-
@Olaf:我在队列中有一个修复格式的编辑。
-
另外,当您可能要检查
count == 0是否是case 'B':时,您正在分配count = 0 -
哪个编译器?哪个平台?信息不足
-
您的 scanf 会覆盖您刚刚生成的随机值。此外,您的一些 printfs 缺少换行符。