菜鸟问问题~~~数组输入,中途退出
#include<iostream>using namespace std;
char name[10][80];
char phone[10][20];
float hours[10];
float wage[10];
int menu();
void enter(),report();
int main()
{
int choice;
do{
choice=menu();
switch(choice) {
case 0:break;
case 1:enter();
break;
case 2:report();
break;
default:cout<<"try again.\n";
}
}while(choice!=0);
return 0;
}
int menu()
{
int choice;
cout<<"0.quit\n";
cout<<"1.enter information\n";
cout<<"2.report information\n";
cout<<"\nchoose one:";
cin>>choice;
return choice;
}
void enter()
{
int i;
[bo] char temp[80];[/bo]
for(i=0;i<10;i++)
{
cout<<"enter last name:";
cin>>name[i];
[bo]if(!name[i]) break;[/bo]
cout<<"enter phone number:";
cin>>phone[i];
cout<<"enter number of hours worked:";
cin>>hours[i];
cout<<"enter wage:";
cin>>wage[i];
}
}
void report()
{
int i;
for(i=0;i<10;i++)
{
cout<<name[i]<<' '<<phone[i]<<'\n';
cout<<"pay for the week:"<<wage[i]*hours[i]<<'\n';
}
}
两个问题:
1,定义temp【80】是干什么的
2,不加if(!name[i]) break;语句时的原程序要连续输入10组数据,我想在直接输入回车后就退出输入了,要加什么语句?
谢谢各位高手