why doesn't this work?
Jun 17, 2009 at 8:06pm UTC
I'm building a banking program for my lab class, i have a problem with part of the code, i made a program out of that code to study it especially, but i cant find the problem... 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
#include<iostream>
using namespace std;
int main()
{
int QC=0,CN,CLI[100];
int X=1;
while (X!=0){
cout<<"Cual sera el numero de cliente? " ;
cin>>CN;
if (CN<10000||CN>99999) {cout<<"Numero invalido \n\n" ;}
else for (int i=0;i<100;i++){if (CN==CLI[i]){cout<<"Cliente ya existe\n\n" ;
break ;}
else {CLI[QC]=CN;
QC++;
cout<<"Cliente creado exitosamente \n\n" ;
break ;}
}
cout<<"Otro? " ;
cin>>X;
}
cout<<"Q= " <<QC<<endl;
for (int i=0;i<=(QC-1);i++){cout<<CLI[i]<<endl;}
system("pause" );
return 0;
}
it's supposed to not let you create the client if it already exists, but it does anyway, i've narrowed the error to be around here:
1 2 3 4 5 6 7
else for (int i=0;i<100;i++){if (CN==CLI[i]){cout<<"Cliente ya existe\n\n" ;
break ;}
else {CLI[QC]=CN;
QC++;
cout<<"Cliente creado exitosamente \n\n" ;
break ;}
}
but i cant see it, can you help me?
thanks!!
Jun 17, 2009 at 8:14pm UTC
never mind, got it :P sorry, thanks
Jun 17, 2009 at 8:15pm UTC
your have no brackets around your else:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
else
{
for (int i=0;i<100;i++)
if (CN==CLI[i])
{
cout<<"Cliente ya existe\n\n" ;
break ; // whats the point of these
}
else
{
CLI[QC]=CN;
QC++;
cout<<"Cliente creado exitosamente \n\n" ;
break ; // ??
}
}
try not to have your code formatting like that anymore,
its almost impossible to read
Last edited on Jun 17, 2009 at 8:16pm UTC
Topic archived. No new replies allowed.