佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 987|回复: 0

帮忙看有什么错误

[复制链接]
发表于 14-3-2009 09:25 PM | 显示全部楼层 |阅读模式
# include <iostream.h>
# include <fstream>
//array sizes
const int NAME_SIZE = 51 , ADDR_SIZE = 51 , PHONE_SIZE = 14 ,MAIL_SIZE=100 , FAC_SIZE=60;
//Declare a structure for the record
struct Info
{
char name[NAME_SIZE] ;
int age ;
char address1[ADDR_SIZE];
char address2[ADDR_SIZE];
char phone[PHONE_SIZE];
char email[MAIL_SIZE];
int ic ;
char faculty[FAC_SIZE];
};
int main ()
{
Info person ;
char again ;
//open a file for binary output .
fstream people("people.dat" , ios:ut|ios::binary) ;
do
{
// Get data about a person .
cout <<"Enter the following data about a person " <<endl;
cout <<"-----------------------------------------\n" ;
cout <<"Name : " ;
cin.getline(person.name,NAME_SIZE);
cout<<"Age : ";
cin>> person.age ;
cin.ignore(); //skip over the remaining newline .
cout << "Address line 1 : " ;
cin.getline(person.address1,ADDR_SIZE);
cout << "Address line 2 : " ;
cin.getline (person.address2,ADDR_SIZE);
cout<< "hone : " ;
cin.getline(person.phone, PHONE_SIZE);
cout<<"email : " ;
cin.getline(person.email,MAIL_SIZE);
cout <<"IC number : " ;
cin >>person.ic ;
cout >>"faculty : " ;
cin.getline(person.faculty,FAC_SIZE) ;

// Write the contents of the person structure to the file.
people.write(reinterpret_cast<char *>(&person),sizeof(person));
// Find out whether the user wants to write another record.
cout << "Do you want to enter another record? (Y/N)" ;
cin>> again ;
cin.ignore(); //Skip over the remaining newline.
}
while (again== 'Y' || again == 'y') ;
//close the file .
people.close() ;
return 0 ;
}




我不知哪里有错误。请帮忙我看以下。。
How can i do when the person enter the code beside Y ?
i means if they enter others word beside y and n , i wan my cout << "You have enter invalid code , pls type it again .."

For the next part , i dunno to verify the person in my database .
Like , When i enter the people name not in my database , how can i write the code ya ?
Thanks for helping me ..
回复

使用道具 举报

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

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


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

GMT+8, 15-12-2025 07:51 AM , Processed in 0.106024 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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