guys take a look to this problem(c2664) about string

guys i wrote down program every thing is fine but that have 4 error , and errors is same with c2664 can u debug it for me !?

thanks for your time :X



#include <iostream.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>

using namespace std;
const int j=100;
void main()
{
int i=0,u=0,tmp=150;
char answer,answer2;
string A[j];
string inf[j];
string B;
do
{
cout<<"ENTER Plaque "<<i+1<<":"<<endl;

cin.getline (cin,A[i]);
cout<<"please Enter information about this car with this format model,ownername...etec"<<endl;
cin.getline (cin,inf[i]);
cout << "Do you want to input one more!? y/n\n";
cin.get(answer);
if (answer == 'y')
{
cout << "Well then What You Waiting For!?input one more\n";
}
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);
cout<<"\n searching begins,Please waiting...";
for(u=0;u<100;u++)
{
if(B==A[u])

{
cout<<"car found,and this car information is:"<<endl;

cout<<cin.getline (cin,inf[u]);

tmp=u;

break;
}

if(tmp==150)
cerr <<"information for "<<B<<"the not found"<<endl;
cout << "Do you want to try one more!? y/n\n";

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');
}

Next time, please post the errors you're getting (c2664 is not very descriptive, nor are there any line numbers) and use code tags.
There are several problems with your code, see the comments below.

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');
    }
}
Last edited on
@kooroshkdt

Your code will not compile if you have void main().

You have an elementary formulation error at lines 76 and 36. You're using the wrong comparison it seems.

Your braces seem to be messed up. I counted 9 { and 8 }.

Aside from that, Athar's suggestions are worth following. Keep it up!

-Albatross

EDIT: 777 posts, and counting. What luck.
Last edited on
Topic archived. No new replies allowed.