1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <iostream.h> //correct name is iostream
#include <string.h> //correct name is cstring - this is a C header, you don't need it anyway
#include <conio.h> //not a standard C++ header
#include <stdio.h> //correct name is cstdio - this is a C header, you don't need it anyway
#include <stdlib.h> //correct name is cstdlib - this is a C header, you don't need it anyway
#include <string>
using namespace std;
const int j=100; //'j' is completely undescriptive
void main() //correct form: int main()
{
int i=0,u=0,tmp=150; //don't declare variables long before you use them - use more descriptive names
char answer,answer2;
string A[j]; //use std::vector instead of arrays. This approach is bad, because you're
string inf[j]; //artificially limiting the max number of inputs that can be made and waste space on the stack
string B;
do
{
cout<<"ENTER Plaque "<<i+1<<":"<<endl;
cin.getline (cin,A[i]); //this should be getline (cin,A[i]);
cout<<"please Enter information about this car with this format model,ownername...etec"<<endl;
cin.getline (cin,inf[i]); //see above
cout << "Do you want to input one more!? y/n\n"; //use endl instead of \n - endl also flushes the stream
cin.get(answer);
if (answer == 'y')
{
cout << "Well then What You Waiting For!?input one more\n"; //see above
}
if (answer == 'n')
{
cout << "very well, As your wish"<<endl;
}
i++;
}
while(answer =='n');
do
{
cout<<"please Enter the car plaque which you want information about it:"<<endl;
cin.getline (cin,B); //see above
cout<<"\n searching begins,Please waiting...";
//u should be declared here
for(u=0; u<100; u++) //no magic numbers, use j instead of 100 (not that 'j' is that much better...)
{
if(B==A[u])
{
cout<<"car found,and this car information is:"<<endl;
cout<<cin.getline (cin,inf[u]); //see above
tmp=u; //you don't need tmp if you declare u outside the loop
break;
}
if(tmp==150) //if (u>=j)...
cerr <<"information for "<<B<<"the not found"<<endl;
cout << "Do you want to try one more!? y/n\n"; //see above
cin.get(answer2);
if (answer2 == 'y')
{
cout << "Well then What You Waiting For!?input one more\n";
}
if (answer2 == 'n')
{
cout << "very well, As your wish"<<endl;
}
i++;
}
while(answer2 == 'n');
}
}
|