学校要交实验,可是根本没学C++就让用VC,自学了一段不过脑袋都大了,请指教
错误在:不能执行新游戏
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <math.h>
#include <process.h>
#include <stdio.h>struct player{
char name[20];
int point;
};
player pA;
bool newplayer,newplay;void Begin();
int listmenu();
void playmain();
void NewPlay();
void endProcess();
void listwins();
void stat_sort();
void listplayers();int main()
{
Begin();
int winsNum = 0;
int gameNumber = 0;
ifstream fileA;
fileA.open("filea.txt");
if(!fileA)
{
cout << "不能打开玩家成绩文件\n";
return 1;
}
player pB;
pA.point = -1;
int tmp;
newplayer = true;
while(!fileA.eof())
{
fileA >> pB.name; fileA >> tmp;
if(strcmp(pA.name,pB.name)==0)
{
pA.point = tmp;
newplayer = false;
break;
}
}
if(newplayer)
{pA.point = 0;}
fileA.close();
newplay = false;
playmain();
return 0;
}
void Begin()
{
cout << "\n\n\n\n\t猜数游戏!"<<"\n\n\t输入你的姓名:";
cin >> pA.name;
}
int listmenu()
{
int s;
do{
system("cls");
cout << "\n\n\t      游戏菜单\n"
<<"\t* * * * * * * * * * * * * * *\n"
<<"\t 1、开始新游戏\n"
<<"\t 2、查看成绩\n"
<<"\t 3、成绩清零\n"
<<"\t 4、退    出\n"
<<"\t 请选择:";
cin >> s;
}while(s<1||s>4);
return s;
}void playmain()
{
int sel;
while(1)
{
sel = listmenu();
switch(sel)
{
case 1: NewPlay();
break;
case 2:listplayers();
break;
case 3: pA.point = 0;break;
case 4: endProcess();return;
}
}
}
void endProcess()
{
fstream fileB;
if(newplayer)
{
fileB.open("filea.txt",ios::out|ios::app);
if(!fileB)
{
cout << "不能打开玩家成绩文件\n";
return;
}
fileB << setiosflags(ios::left) << setw(20) << pA.name << setw(10) << pA.point << endl;
}
else
{
fileB.open("filea.txt",ios::out|ios::in);
if(!fileB)
{
cout << "不能打开玩家成绩文件\n";
return;
}
player pt;char tp[30];
while(!fileB.eof())
{
fileB >> pt.name;
fileB.getline(tp,30);
if(strcmp(pA.name,pt.name)==0)
{
fileB.seekp(-32,ios::cur);
fileB << setiosflags(ios::left) << setw(20) << pA.name << setw(10) << pA.point << endl;
break;
}
}
}
fileB.close();
cout << "\n\n\n\t Bye-Bye!";
}
void listplayers()
{
ifstream fileC;
fileC.open("filea.txt");
if(!fileC)
{
cout << "不能打开玩家成绩文件\n";
return;
}
char tp[20];
player pC;
cerr << "\n\t玩家成绩\n";
while(!fileC.eof())
{
fileC >> pC.name;
fileC >> pC.point;
fileC.getline(tp,20);
cout << setw(14) << pC.name << setw(8) << pC.point <<endl;
}
fileC.close();
cerr << "按下任意键继续...";
getch();
}void NewPlay()
{
int answer[4],guess=0,a,b,times=0,i,j;
for(i=0;i<=3;i++)
{

answer[i]=rand()%10;
for(j=0;j<1;j++)
{
while(answer[i]==answer[j])
{
answer[i]=rand()%10;
j=-1;
}
}
} cout << "请开始Guess\n";
while(a!=4)
{
a=0;
b=0;
times++;
do{
cout << times << "   ";
cin >> guess;
if(guess == 0)
exit(0);
}while(guess<0||guess>9999);
for(i=3;i>-1;i--)
{
for(j=0;j<4;j++)
{
if((int)(guess/pow(10,i)) == answer[j])
{
if(i+j ==3) a=a+1;
else b=b+1;
}
}
guess = guess -(int)(guess/pow(10,i))*pow(10,i);
}
cout << a << "A" << b << "B";
}
}

解决方案 »

  1.   

    // ttt.cpp : Defines the entry point for the console application.
    //#include "stdafx.h"
    /*int main(int argc, char* argv[])
    {
    return 0;
    }
    */
    #include <iostream.h>
    #include <iomanip.h>
    #include <fstream.h>
    #include <string.h>
    #include <stdlib.h>
    #include <time.h>
    #include <conio.h>
    #include <math.h>
    #include <process.h>
    #include <stdio.h>struct player{
    char name[20];
    int point;
    };
    player pA;
    bool newplayer,newplay;void Begin();
    int listmenu();
    void playmain();
    void NewPlay();
    void endProcess();
    void listwins();
    void stat_sort();
    void listplayers();int main()
    {
    Begin();
    int winsNum = 0;
    int gameNumber = 0;
    ifstream fileA;
    fileA.open("filea.txt");
    if(!fileA)
    {
    cout << "不能打?玩家成?文件\n";
    return 1;
    }
    player pB;
    pA.point = -1;
    int tmp;
    newplayer = true;
    while(!fileA.eof())
    {
    fileA >> pB.name; fileA >> tmp;
    if(strcmp(pA.name,pB.name)==0)
    {
    pA.point = tmp;
    newplayer = false;
    break;
    }
    }
    if(newplayer)
    {pA.point = 0;}
    fileA.close();
    newplay = false;
    playmain();
    return 0;
    }
    void Begin()
    {
    cout << "\n\n\n\n\t猜?游?!"<<"\n\n\t?入你的姓名:";
    cin >> pA.name;
    }
    int listmenu()
    {
    int s;
    do{
    system("cls");
    cout << "\n\n\t      游?菜?\n"
    <<"\t* * * * * * * * * * * * * * *\n"
    <<"\t 1、?始新游?\n"
    <<"\t 2、查看成?\n"
    <<"\t 3、成?清零\n"
    <<"\t 4、退    出\n"
    <<"\t ???:";
    cin >> s;
    }while(s<1||s>4);
    return s;
    }void playmain()
    {
    int sel;
    while(1)
    {
    sel = listmenu();
    switch(sel)
    {
    case 1: NewPlay();
    break;
    case 2:listplayers();
    break;
    case 3: pA.point = 0;break;
    case 4: endProcess();return;
    }
    }
    }
    void endProcess()
    {
    fstream fileB;
    if(newplayer)
    {
    fileB.open("filea.txt",ios::out|ios::app);
    if(!fileB)
    {
    cout << "不能打?玩家成?文件\n";
    return;
    }
    fileB << setiosflags(ios::left) << setw(20) << pA.name << setw(10) << pA.point << endl;
    }
    else
    {
    fileB.open("filea.txt",ios::out|ios::in);
    if(!fileB)
    {
    cout << "不能打?玩家成?文件\n";
    return;
    }
    player pt;char tp[30];
    while(!fileB.eof())
    {
    fileB >> pt.name;
    fileB.getline(tp,30);
    if(strcmp(pA.name,pt.name)==0)
    {
    fileB.seekp(-32,ios::cur);
    fileB << setiosflags(ios::left) << setw(20) << pA.name << setw(10) << pA.point << endl;
    break;
    }
    }
    }
    fileB.close();
    cout << "\n\n\n\t Bye-Bye!";
    }
    void listplayers()
    {
    ifstream fileC;
    fileC.open("filea.txt");
    if(!fileC)
    {
    cout << "不能打?玩家成?文件\n";
    return;
    }
    char tp[20];
    player pC;
    cerr << "\n\t玩家成?\n";
    while(!fileC.eof())
    {
    fileC >> pC.name;
    fileC >> pC.point;
    fileC.getline(tp,20);
    cout << setw(14) << pC.name << setw(8) << pC.point <<endl;
    }
    fileC.close();
    cerr << "按下任意???...";
    getch();
    }void NewPlay()
    {
    int t;
    int answer[4],guess=0,a,b,times=0,i,j;
    for(i=0;i<=3;i++)
    {
    answer[i]=rand()%10;
    for(j=0;j<i;j++)
    {
    while(answer[i]==answer[j])
    {
    answer[i]=(rand()*10)%10;
    }
    }
    } cout << "??始Guess\n";
    a = 0;
    while(a!=4)
    {
    a=0;
    b=0;
    times++;
    do{
    cout << times << "   ";
    cin >> guess;
    if(guess == 0)
    exit(0);
    }while(guess<0||guess>9999);
    for(i=3;i>-1;i--)
    {
    for(j=0;j<4;j++)
    {
    int t;
    t = (int)(guess/pow(10,i)); 
    if((int)(guess/pow(10,i)) == answer[j])
    {
    if(i+j ==3) a=a+1;
    else b=b+1;
    }
    }
    guess = guess -(int)(guess/pow(10,i))*pow(10,i);
    }
    cout << a << "A" << b << "B";
    }
    }
      

  2.   

    不好意思我不是程序员,加的那个
    #include "stdafx.h"
    /*int main(int argc, char* argv[])
    {
    return 0;
    }有什么用呢另外怎么给你加分,我去试一下
      

  3.   

    Cannot open include file: 'stdafx.h': No such file or directory
      

  4.   

    stdafx是系统加上的,不是随便加就行的。
      

  5.   

    jennyvenus(围巾是个大头鬼) 真幽默呀!
      

  6.   

    换成猜字母怎么改?
    正在加分
     DoubleJiang(Double) THX
      

  7.   


     DoubleJiang(Double) 不好意思,现在加分就要结束帖子了,能不能给我换成猜字母,如果可以的话。
    不能请留言,好给你加分和结束帖子。