Thứ Tư, 11 tháng 3, 2015

5. Viết chương trình nhập họ tên, điểm toán, điểm văn của một học sinh. Tính điểm trung bình và xuất kết quả.

#include<iostream>
using namespace std;
struct hs
{
char ten[100];
float toan,van;
};
void nhap(hs &x);
float dtb(hs x);
void main()
{
hs x;
nhap(x);
cout<<"\ndiem trung binh la: "<<dtb(x);
system("pause");
}
void nhap(hs &x)
{
int kt;
cout<<"\nnhap ten: ";
fflush(stdin);gets(x.ten);
do{
kt=0;
cout<<"\ndiem toan: ";cin>>x.toan;
if(x.toan<0 || x.toan>10)
{
kt=1;cout<<"\nkhong hop le!";
}
}while(kt);
do{
kt=0;
cout<<"\ndiem van: ";cin>>x.van;
if(x.van<0 || x.van>10)
{
kt=1;cout<<"\nkhong hop le!";
}
}while(kt);
}
float dtb(hs x)
{
return (x.toan+x.van)/2;
}

Không có nhận xét nào:

Đăng nhận xét