logical error!

the compiler doesnt display error so i dont know if there's one...... here's the code::

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
int addsup()
{
   int f, n;
   sup s1[x],s2[x],s[10];
   ifstream flin("supplier.dat", ios::in);
   ofstream fout("temp.dat", ios::out);
   if(!flin || !fout)
  {
    cout<<"\nUNABLE 2 OPEN FILES \n";
    return 1;
  }
   cout<<"no of suppliers u wish 2 add ?";
   cin>>n;
   for(int i=0; i<n; i++)
  {
    cout<<"Supplier::\n";
    f = 0;
    s2[i].getdata();
    flin.seekg(0);
    int j=0;
    while(!flin.eof() && f != 1)
    { flin.read((char*) &s1[j],sizeof(s1[j]));
       cout<<"\nhello\n";
      if (s2[i].putid()==s1[j].putid())
      f=1;
      j++;
  }
  if(f)
  {
    cout<<"SUPPLIER ID EXISTS!!!";
  }
  else
  fout.write((char*) &s2[i],sizeof(s2[i]));
 }
 fout.close();
 flin.close();
 fout.open("supplier.dat", ios::app);
 flin.open("temp.dat",ios::in);
 int k=0;
 while(!flin.eof())
 {
    flin.read((char*) &s[k],sizeof(s[k]));
    fout.write((char*) &s[k],sizeof(s[k]));
    k++;
 }
 int y=2;
 return y;
}
Last edited on
whenever you post code, copy from your editor and paste it here so that indentation is saved. and then select the whole code and press <> on the right side. This will give your code a good representation. If you post this way, no one will reply as the code is not readable.

Now do it!!
sorry for the haphazard post as it was my first time.. n thanks 4 the tip. looking forward to your reply
Last edited on

sup s1[x],s2[x],s[10]; - type missing (is sup a type?). Also, you can only use constants to declare the arrays, so remove x and put some constants. x is also not declared. You can declare the x as const and can use it then.

for logical error's you have to tell what you are trying to do here?
Topic archived. No new replies allowed.