C++打字游戏的代码调试

来源:百度知道 编辑:UC知道 时间:2024/07/07 00:58:57
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
void GetCharacter(int n)
{
extern char outstr[];
FILE *fp;
if(n==1)
fopen_s(&fp,"english.txt","r");
else if(n==2)
fopen_s(&fp,"other.txt","r");
else if (n==3)
fopen_s(&fp,"typeall.txt","r");

int choice;
printf("please choose the mount of MaxCharacter you want:\n");
printf("1.50\t 2.100\t 3.200\t 4.300\t 5.self-defined(<1000)\t");
getch();
scanf_s("%d",&choice);
int MaxChar;
switch(choice)
{
case 1: MaxChar=50; break;
case 2: MaxChar=100;break;
case 3: MaxChar=200;break;
case 4: MaxChar=300;break;
case 5: getchar();scanf_s("%d",&MaxChar);break;
}

int i;
srand(155);

getch();
scanf_s("%d",&choice);
这两句有重复啊,去掉getch()

switch(choice)
{
case 1: MaxChar=50; break;
case 2: MaxChar=100;break;
case 3: MaxChar=200;break;
case 4: MaxChar=300;break;
case 5: getchar();scanf_s("%d",&MaxChar);break;
}

case5:后面也去掉 getchar();

scanf_s()就有接受输入的功能

你最好把代码全部都贴出来,这样才能好找错误,现在不好说,可能是程序其他方面的问题。。