关闭。这个问题需要debugging details .它目前不接受答案。
想改进这个问题?将问题更新为 on-topic对于堆栈溢出。
6年前关闭。
Improve this question
我试图帮助 friend 完成他的考试,用 C++ 创建这个考试评分程序,但所有尝试都未能编译这个程序。你能帮助我吗?
每次尝试总是得到“ fatal error ”和“没有这样的文件或目录
编译终止。” 到目前为止,我们尝试使用在线编译器对其进行编译。
# include <stdio.h>
# include <iostream.h>
# include <conio.h>
main()
{
char nama[20],*Grade;
float nk,nt,nu,nmk,nmt,nmu,na;
cout<<"Program Hitung Nilai Akhir Siswa"<<endl<<endl;
cout<<" Masukkan Nama Siswa : ";gets(nama);
cout<<" Nilai Keaktifan : ";cin>>nk;
cout<<" Nilai Tugas : ";cin>>nt;
cout<<" Nilai Ujian : ";cin>>nu;
nmk=nk*0.2;
nmt=nt*0.3;
nmu=nu*0.5;
na=nmk+nmt+nmu;
if(na>=80)a
{
Grade="A";
}
else if(na>=90)
{
Grade="B";
}
else if(na>=80)
{
Grade="C";
}
else if(na>=70)
{
Grade="D";
}
else
{
Grade="E";
}
cout<<endl;
cout<<" Siswa Yang Bernama "<<nama<<endl;
cout<<" Dengan nilai presentase yang dihasilkan"<<endl;
cout<<" Nilai Murni Keaktifan x 20% : "<<nmk<<endl;
cout<<" Nilai Murni Tugas x 30% : "<<nmt<<endl;
cout<<" Nilai Murni Ujian x 50% : "<<nmu<<endl;
cout<<" Memperoleh Nilai Akhir Sebesar : "<<na<<endl;
cout<<" Grade yang di dapat : "<<Grade<<endl;
getch();
}
最佳答案
大多数在线编译器使用最新的 C++ 标准。他们很可能不支持旧式 C++ 程序。
你可以改变的事情开始......
#include
行
代替
# include <stdio.h>
# include <iostream.h>
采用
# include <cstdio>
# include <iostream>
不要使用非标准标题
消除
# include <conio.h>
cin
和 cout
在 std
命名空间 更改
cin
的所有用法通过 std::cin
以及 cout
的所有用法通过 std::cout
.你也可以使用using namespace std;
避免使用
std::cin
和 std::cout
.但是,不要在任何地方都使用这种机制,以避免输入额外的 std::
。 .不要使用
gets
使用
gets
是已知的安全漏洞来源。不要使用它。将其用法替换为
fgets
.代替
cout<<" Masukkan Nama Siswa : ";gets(nama);
你可以使用
cout<<" Masukkan Nama Siswa : ";
fgets(nama, sizeof(nama), stdin);
但是,这也不好,因为您正在混合使用
stdin
和 cin
获取用户输入。要么坚持使用 stdio.h
中的函数或使用 cin
获取用户输入。您可以使用: cout<<" Masukkan Nama Siswa : ";
cin.get(nama, sizeof(nama));
使用
std::string
而不是 char*
保持字符串改变
char nama[20],*Grade;
到
char nama[20];
std::string Grade;
不要使用非标准函数
删除线
getch();
关于c++ - 如何在 C++ 中创建考试评分程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36183146/