首先 thnx 试图帮助我.....这是我程序的一部分......我想知道如何在 main() 中输入数据时进行验证......thnx
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
int i;
class product //start of class
{
int itemno;
char name[100];
char itemtype[50];
float price;
float quantity;
float total;
public:
void addprod() ;
void calculate();
void accept();
void display() ;
} ; //end of class
void product::addprod() //starting of addproduct()
{
cout<<"enter the serial number";
cin>>itemno;
cout<<"enter the name of the poduct:";
gets(name) ;
cout<<"enter its type:";
gets(itemtype);
***cout<<"enter its price:";
cin>>price;**
}* //end of addproduct()
void product::accept() //starting of accept()
{
cout<<"enter the item name:";
gets(name) ;
cout<<"enter the quantity:";
cin>>quantity;
}
void product::calculate()
{
total=price*quantity;
}
void product::display()
{
cout<<"\nName";
cout<<name;
cout<<"\nPrice";
cout<<price ;
cout<<"\nquantity";
cout<<quantity;
cout<<"\ntotal\n\n\n\n\n";
cout<<total;
}
void main()
{
int ch;
product s1[3];
a:
cout<<"\n 1. Add product one by one";
cout<<"\n 2. Add products in bulk";
cout<<"\n 3. Make Bill";
cout<<"\n 4. Display Bill";
cout<<"\n 0. Exit";
cout<<"\n Enter your choise(1,2,3,9)" ;
cin>>ch;
switch(ch)
{
**case 1: cout<<"\n press n to exit\n\n";
char con='y';
while(con=='y')
{
s1[i].addprod();
i++;
cout<<"do u wanna continue(y/n)";
cin>>con;
if(con=='n')
{
goto a;
}
}
break;
}**
这是我的学校项目,所以需要尽快帮助。就像如果一个人输入一个字符(a,b,c)那么我应该怎么做才能让他意识到它的输入错误并要求用户输入正确的形式