[ create a new paste ] login | about

Link: http://codepad.org/PCGY7JUX    [ raw code | output | fork | 2 comments ]

C, pasted on Sep 14:
#include<stdio.h>
#include<conio.h>
#include<string.h>
char hoten [30];
int toan;
int van;
float DiemTrungBinh;

void Nhap()
{
	fflush(stdin);
	printf("\nNhap ho ten: ");
	gets(hoten);

	printf("\nNhap toan: ");
	scanf("%d", &toan);

	printf("\nNhap van: ");
	scanf("%d", &van);
}

void XuLy()
{
	DiemTrungBinh = (toan + van) / 2.0;
}

void Xuat()
{
	printf("\nHo ten: %s", hoten);
	printf("\nToan: %d", toan);
	printf("\nVan: %d", van);
	printf("\nDiem Trung Binh: %f", DiemTrungBinh);
}
int main()
{
	Nhap();
	XuLy();
	Xuat();

	getch();
	return 0;
}


Output:
1
Line 17: error: conio.h: No such file or directory


Create a new paste based on this one


Comments:
posted by Dgls on Feb 19
#include<iostream>
using namespace std;
struct hs{
char ten[30];
float toan, van;
};
void nhap(hs &x){
cout<<"Nhap ten hoc sinh: ";
fflush(stdin); gets(x.ten);
cout<<"Diem Toan:" ; cin>>x.toan;
if (x.toan<0||x.toan>10){
cout<<"Diem toan nhap sai, nhap lai: "; cin>>x.toan;
}
cout<<"Diem Van: "; cin>>x.van;
if (x.van<0||x.van>10){
cout<<"Diem van nhap sai, nhap lai: "; cin>>x.van;
}
}
float diemtb(hs x){
return (x.toan+x.van)/2;
}
main(){
hs x;
nhap(x);
cout<<"Diem trung binh la: "<<diemtb(x)<<endl;
}
reply
posted by yonnon on Aug 1
#include<bits/stdc++.h>
#define MAX 100
using namespace std;
struct Student
{
string name;
float scoremath;
float scorevan;
float average;

void getinfomation()
{
cin.ignore(1);
cout << "Name = ";
getline(cin, name);
cout << "Toan = ";
cin >> scoremath;
cout << "Van = ";
cin >> scorevan;
cout<<"\n";
}

void display()
{
cout << "Name = "<<name<<
endl;
cout << "Toan = "<<scoremath<<
endl;
cout << "Van = "<<scorevan<<
endl;
cout << "DTB = "<<(static_cast<float>(scoremath) + scorevan)/2<<
endl;
}
};

int main()
{
int n;
cout << "Enter your sentence: ";
cin >> n;
Student *students = new Student[MAX];

for(int i = 0; i < n ; ++i)
{
students[i].getinfomation();
}
for(int i = 0; i < n ; ++i)
{
students[i].display();
}

delete[] students;
return 0;
}
reply