佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 822|回复: 9

请大家来帮忙解决C++程序里的9个errors

[复制链接]
该用户已被删除
发表于 25-2-2006 07:43 PM | 显示全部楼层 |阅读模式
以下的程序码有9个errors,
可否请大家告诉我怎么解决?
有劳各位了。。


  1. #include <iostream.h>
  2. #include <fstream.h>
  3. void main()
  4. {
  5.         fstream hasil;       
  6.         int BilUndian;
  7.         int Jumlah=0;
  8.         char Nama [20];
  9.         char NamaCalon [20];
  10.         double PeratusUndian;
  11.         hasil.open (" hasil.dat ", ios::out);
  12.        
  13.         cout<< " Masukkan nama calon : "<<NamaCalon;
  14.         cin>>Nama;
  15.         cout<< " Masukkan bil undian : "<<BilUndian;
  16.         cin>>BilUndian;

  17.         for (int i; i<=15; i++)
  18.         {
  19.                 Jumlah=Jumlah + BilUndian;               
  20.                 hasil<<NamaCalon<< " "<<BilUndian<<endl;
  21.         }

  22.         hasil.close();

  23.         paparCalon (Jumlah);
  24.         Pemenang ();
  25. }

  26. void paparCalon (int jum)
  27. {
  28.         int BilUndian;
  29.         int Jumlah=0;
  30.         double PeratusUndian;
  31.         fstream hasil;
  32.         hasil.open ( " hasil.dat ", ios::in);

  33.                 if (hasil.open.fail())
  34.                 {
  35.                         cerr<<" Ralat semasa membaca fail "<<"hasil.dat";
  36.                         exit (-1);
  37.                 }

  38.         hasil<<Nama<<BilUndian<<endl;

  39.         cout<<" Calon "<<" "<<" Undian_Diterima "<<" "<<" % daripada Undian diterima "<<endl;

  40.         while (!hasil.eof())
  41.         {
  42.                 PeratusUndian = BilUndian/Jumlah*0.01;
  43.                 cout<<"Nama"<<" "<<"BilUndian"<<" "<<"PeratusUndian"<<endl;
  44.                 hasil>>Nama>>BilUndian;
  45.         }

  46.         hasil.close ();
  47. }

  48. void Pemenang ()
  49. {
  50.         char Nama_Pemenang [20];
  51.         char Nama [20];
  52.         int  BilUndian;
  53.         int  Undi;
  54.         float PeratusUndian;
  55.         fstream hasil;
  56.         hasil.open (" hasil.dat ", ios::in);

  57.         if (hasil.open.fail())
  58.         {
  59.                 cerr<<" Ralat semasa membaca fail "<< "hasil.dat";
  60.                 exit (-1);
  61.         }

  62.         hasil>>Nama>>BilUndian;
  63.         Undi=BilUndian;
  64.         strcpy (Nama_Pemenang, Nama);
  65.        
  66.         while (!hasil.eof())
  67.         {
  68.                 hasil>>Nama>>BilUndian;
  69.                 if (Undi<BilUndian)
  70.                 {
  71.                         Undi=BilUndian;
  72.                         strcpy (Nama_Pemenang, Nama);
  73.                 }
  74.         }

  75.         cout<<" Pemenang Pilihanraya adalah : "<< Nama_Pemenang;

  76.         hasil.close();
  77. }

复制代码
回复

使用道具 举报


ADVERTISEMENT

arcanesky 该用户已被删除
发表于 25-2-2006 10:21 PM | 显示全部楼层
function 是無法辯認 另個function 的variable的.
所以void main()和void pemenang()裏的Nama 不能在void Pemenang ()被識別。

除非利用function的argument形式讀取
或是利用C++的強力工具 class

另外 hasil.open.fail()不知道可不可以用。
試試 !hasil.is_open()
或是 hasil.fail()
回复

使用道具 举报

发表于 25-2-2006 11:04 PM | 显示全部楼层
hasil.open ( " hasil.dat ", ios::in);
可能有问题..应该 hasil.open ( "hasil.dat", ios::in);

是否也应该将 Error Msg 也贴出来呢?
回复

使用道具 举报

该用户已被删除
 楼主| 发表于 25-2-2006 11:58 PM | 显示全部楼层
原帖由 jasonmun 于 25-2-2006 11:04 PM 发表
hasil.open ( " hasil.dat ", ios::in);
可能有问题..应该 hasil.open ( "hasil.dat", ios::in);

是否也应该将 Error Msg 也贴出来呢?




  1. --------------------Configuration: Pemenang - Win32 Debug--------------------
  2. Compiling...
  3. Pemenang.cpp
  4. c:\documents and settings\fan_2\desktop\c++\pemenang.cpp(26) : error C2065: 'paparCalon' : undeclared identifier
  5. c:\documents and settings\fan_2\desktop\c++\pemenang.cpp(27) : error C2065: 'Pemenang' : undeclared identifier
  6. c:\documents and settings\fan_2\desktop\c++\pemenang.cpp(31) : error C2373: 'paparCalon' : redefinition; different type modifiers
  7. c:\documents and settings\fan_2\desktop\c++\pemenang.cpp(38) : error C2228: left of '.fail' must have class/struct/union type
  8. c:\documents and settings\fan_2\desktop\c++\pemenang.cpp(41) : error C2065: 'exit' : undeclared identifier
  9. c:\documents and settings\fan_2\desktop\c++\pemenang.cpp(44) : error C2065: 'Nama' : undeclared identifier
  10. c:\documents and settings\fan_2\desktop\c++\pemenang.cpp(59) : error C2373: 'Pemenang' : redefinition; different type modifiers
  11. c:\documents and settings\fan_2\desktop\c++\pemenang.cpp(68) : error C2228: left of '.fail' must have class/struct/union type
  12. c:\documents and settings\fan_2\desktop\c++\pemenang.cpp(76) : error C2065: 'strcpy' : undeclared identifier
  13. Error executing cl.exe.

  14. Pemenang.obj - 9 error(s), 0 warning(s)
复制代码
回复

使用道具 举报

发表于 26-2-2006 12:33 AM | 显示全部楼层
#include <iostream>
#include <fstream>

using namespace std;
void paparCalon (int);  //any function written after main() must be declare first
void Pemenang ();

char Nama [20];   //make this as global variable


int main()
{
        fstream hasil;        
        int BilUndian;
        int Jumlah=0;

        char NamaCalon [20];
        double PeratusUndian;
        hasil.open (" hasil.dat ", ios:ut);
        
        cout<< " Masukkan nama calon : "<<NamaCalon;
        cin>>Nama;
        cout<< " Masukkan bil undian : "<<BilUndian;
        cin>>BilUndian;

        for (int i; i<=15; i++)
        {
                Jumlah=Jumlah + BilUndian;               
                hasil<<NamaCalon<< " "<<BilUndian<<endl;
        }

        hasil.close();

        paparCalon (Jumlah);
        Pemenang ();
}

void paparCalon (int jum)
{
        int BilUndian;
        int Jumlah=0;
        double PeratusUndian;
        fstream hasil;
        hasil.open ( " hasil.dat ", ios::in);

                if (hasil.fail())
                {
                        cerr<<" Ralat semasa membaca fail "<<"hasil.dat";
                        exit (-1);
                }

        hasil<<Nama<<BilUndian<<endl;

        cout<<" Calon "<<" "<<" Undian_Diterima "<<" "<<" % daripada Undian diterima "<<endl;

        while (!hasil.eof())
        {
                PeratusUndian = BilUndian/Jumlah*0.01;
                cout<<"Nama"<<" "<<"BilUndian"<<" "<<"eratusUndian"<<endl;
                hasil>>Nama>>BilUndian;
        }

        hasil.close ();
}

void Pemenang ()
{
        char Nama_Pemenang [20];
        char Nama [20];
        int  BilUndian;
        int  Undi;
        float PeratusUndian;
        fstream hasil;
        hasil.open (" hasil.dat ", ios::in);

        if (hasil.fail())
        {
                cerr<<" Ralat semasa membaca fail "<< "hasil.dat";
                exit (-1);
        }

        hasil>>Nama>>BilUndian;
        Undi=BilUndian;
        strcpy (Nama_Pemenang, Nama);
        
        while (!hasil.eof())
        {
                hasil>>Nama>>BilUndian;
                if (Undi<BilUndian)
                {
                        Undi=BilUndian;
                        strcpy (Nama_Pemenang, Nama);
                }
        }

        cout<<" Pemenang Pilihanraya adalah : "<< Nama_Pemenang;

        hasil.close();
}

ps:我是用dev-cpp IDE来compile的,没问题。。。

[ 本帖最后由 titanhrk 于 26-2-2006 12:36 AM 编辑 ]
回复

使用道具 举报

该用户已被删除
 楼主| 发表于 26-2-2006 12:59 AM | 显示全部楼层
原帖由 titanhrk 于 26-2-2006 12:33 AM 发表
#include <iostream>
#include <fstream>

using namespace std;
void paparCalon (int);  //any function written after main() must be declare first
void Pemenang ();

char  ...


可是大大
我copy paste了你的编码
compile时却。。。



  1. --------------------Configuration: Pemenang - Win32 Debug--------------------
  2. Compiling...
  3. Pemenang.cpp
  4. C:\Documents and Settings\Fan_2\Desktop\Pemenang.cpp(18) : warning C4101: 'PeratusUndian' : unreferenced local variable
  5. C:\Documents and Settings\Fan_2\Desktop\Pemenang.cpp(72) : warning C4101: 'PeratusUndian' : unreferenced local variable
  6. C:\Documents and Settings\Fan_2\Desktop\Pemenang.cpp(23) : warning C4700: local variable 'BilUndian' used without having been initialized
  7. C:\Documents and Settings\Fan_2\Desktop\Pemenang.cpp(52) : warning C4700: local variable 'BilUndian' used without having been initialized

  8. Pemenang.obj - 0 error(s), 4 warning(s)
复制代码
回复

使用道具 举报

Follow Us
发表于 26-2-2006 08:33 PM | 显示全部楼层
不好意思,其实我也没真正去看你的code,只是抄过去我用的IDE再修改compile time error罢了。。。你用的是什么compiler?
回复

使用道具 举报

该用户已被删除
 楼主| 发表于 26-2-2006 08:58 PM | 显示全部楼层
原帖由 titanhrk 于 26-2-2006 08:33 PM 发表
不好意思,其实我也没真正去看你的code,只是抄过去我用的IDE再修改compile time error罢了。。。你用的是什么compiler?


visual C++
回复

使用道具 举报


ADVERTISEMENT

发表于 27-2-2006 04:20 PM | 显示全部楼层
原帖由 于 26-2-2006 08:58 PM 发表


visual C++


OK 料 .. 没 WARNING 了。。

#include <iostream>
#include <fstream>

using namespace std;
void paparCalon (int);  //any function written after main() must be declare first
void Pemenang ();

char Nama [20];   //make this as global variable


int main()
{
        fstream hasil;        
        int BilUndian=0;
        int Jumlah=0;

        char NamaCalon [20];
        double PeratusUndian=0.0;
        hasil.open ("hasil.dat", ios:ut);
        
        cout<< " Masukkan nama calon : "<<NamaCalon;
        cin>>Nama;
        cout<< " Masukkan bil undian : "<<BilUndian;
        cin>>BilUndian;

        for (int i; i<=15; i++)
        {
                Jumlah=Jumlah + BilUndian;               
                hasil<<NamaCalon<< " "<<BilUndian<<endl;
        }

        hasil.close();

        paparCalon (Jumlah);
        Pemenang ();
                return 0;
}

void paparCalon (int jum)
{
        int BilUndian=0;
        int Jumlah=0;
        double PeratusUndian;
        fstream hasil;
        hasil.open ( " hasil.dat ", ios::in);

                if (hasil.fail())
                {
                        cerr<<" Ralat semasa membaca fail "<<"hasil.dat";
                        exit (-1);
                }

        hasil<<Nama<<BilUndian<<endl;

        cout<<" Calon "<<" "<<" Undian_Diterima "<<" "<<" % daripada Undian diterima "<<endl;

        while (!hasil.eof())
        {
                PeratusUndian = BilUndian/Jumlah*0.01;
                cout<<"Nama"<<" "<<"BilUndian"<<" "<<"eratusUndian"<<endl;
                hasil>>Nama>>BilUndian;
        }

        hasil.close ();
}

void Pemenang ()
{
        char Nama_Pemenang [20];
        char Nama [20];
        int  BilUndian;
        int  Undi;
        float PeratusUndian=0;
        fstream hasil;
        hasil.open (" hasil.dat ", ios::in);

        if (hasil.fail())
        {
                cerr<<" Ralat semasa membaca fail "<< "hasil.dat";
                exit (-1);
        }

        hasil>>Nama>>BilUndian;
        Undi=BilUndian;
        strcpy (Nama_Pemenang, Nama);
        
        while (!hasil.eof())
        {
                hasil>>Nama>>BilUndian;
                if (Undi<BilUndian)
                {
                        Undi=BilUndian;
                        strcpy (Nama_Pemenang, Nama);
                }
        }

        cout<<" Pemenang Pilihanraya adalah : "<< Nama_Pemenang;

        hasil.close();
}
回复

使用道具 举报

发表于 27-2-2006 04:23 PM | 显示全部楼层
COMPILE 是 OK 了。。
不过你的 PROGRAM 很有问题。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 22-9-2024 01:33 AM , Processed in 0.106526 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表