#include<fstream>
#include<iostream>
#include<string>
using namespace std;
int main ()
{
struct Candidate{
char RegNomer[4];
char name[60];
char party[60];
char age[3];
char xp[3];
long int votes;
}candidate[200];
int i=-1;
int i1=0;
int check=0;
char choice[1];
while (true)
{
system ("cls");
cout<<"/============\\=/============\\=/============\\=/============\\=/============\\ "<<"\n";
cout<<"| save | | create a | | banned | | scoreboard | | ties | "<<"\n";
cout<<"| | | candidate | | candidates | | | | | "<<"\n";
cout<<"| 1 | | 2 | | 3 | | 4 | | 5 | "<<"\n";
cout<<"\\============/ \\============/ \\============/ \\============/ \\============/ "<<"\n";
do{
cout<<"|Please choose an option:";
cin>>choice;
}while ((atoi(choice)<0)||(atoi(choice)>5)); // i have only 5 optsions
if ((atoi(choice)==1))
{
}
if ((atoi(choice)==2))
{
i++; cin.clear();cin.sync();
do{
cout<<"|Enter the candidate's Registration Number:";
cin>>candidate[i].RegNomer;
}while ((candidate[i].RegNomer[0]<'a')||(candidate[i].RegNomer[0]>'z')||(candidate[i].RegNomer[1]<'0')||(candidate[i].RegNomer[1]>'9')||(candidate[i].RegNomer[2]<'0')||(candidate[i].RegNomer[2]>'9')||(candidate[i].RegNomer[3]<'0')||(candidate[i].RegNomer[3]>'9')); // the RegNomer consist of a small letter + 3 digits for instance: s123
cout<<"candidate[i].RegNomer="<<candidate[i].RegNomer<<endl;
check=0; cin.clear();cin.sync();
cout<<"candidate[i].RegNomer="<<candidate[i].RegNomer<<endl;
cout<<"candidate[check].RegNomer="<<candidate[check].RegNomer<<endl;
while (check<i-1)
{
if ((candidate[check].RegNomer[0]==candidate[i].RegNomer[0])&&(candidate[check].RegNomer[1]==candidate[i].RegNomer[1])&&(candidate[check].RegNomer[2]==candidate[i].RegNomer[2])&&(candidate[check].RegNomer[3]==candidate[i].RegNomer[3]))
{cout<<"If-a se izpulni\n";
cout<<"|Another candidate is already using this Registration Number.\n";
do{
cout<<"|Enter the candidate's Registration Number:";
cin>>candidate[i].RegNomer;
cin.clear();cin.sync();
}while (((candidate[i].RegNomer[0]<'a')||(candidate[i].RegNomer[0]>'z')||(candidate[i].RegNomer[1]<'0')||(candidate[i].RegNomer[1]>'9')||(candidate[i].RegNomer[2]<'0')||(candidate[i].RegNomer[2]>'9')||(candidate[i].RegNomer[3]<'0')||(candidate[i].RegNomer[3]>'9'))&&((candidate[check].RegNomer[0]==candidate[i].RegNomer[0])&&(candidate[check].RegNomer[1]==candidate[i].RegNomer[1])&&(candidate[check].RegNomer[2]==candidate[i].RegNomer[2])&&(candidate[check].RegNomer[3]==candidate[i].RegNomer[3])));
} //here i check if the candidate's number is not already taken.
check++;
}
cin.clear();cin.sync();
cout<<"|Enter the candidate's name:";
cin.getline(candidate[i].name,60);
cout<<"candidate[i].RegNomer="<<candidate[i].RegNomer<<endl;
cout<<"candidate[check].RegNomer="<<candidate[check].RegNomer<<endl;
cout<<"candidate[i].name="<<candidate[i].name<<endl;
cout<<"candidate[check].name="<<candidate[i].name<<endl;
cin.clear();cin.sync();
cout<<"|Enter the candidate's political party:";
cin.getline(candidate[i].party,60);
cout<<"candidate[i].RegNomer="<<candidate[i].RegNomer<<endl;
cout<<"candidate[check].RegNomer="<<candidate[check].RegNomer<<endl;
cout<<"candidate[i].name="<<candidate[i].name<<endl;
cout<<"candidate[check].name="<<candidate[i].name<<endl;
cout<<"candidate[i].party="<<candidate[i].party<<endl;
cout<<"candidate[check].party="<<candidate[check].party<<endl;
cin.clear();cin.sync();
do{
cout<<"|Enter the age of the candidate:";
cin>>candidate[i].age;
}while((atoi(candidate[i].age)<1)||(atoi(candidate[i].age)>200));
cout<<"candidate[i].RegNomer="<<candidate[i].RegNomer<<endl;
cout<<"candidate[check].RegNomer="<<candidate[check].RegNomer<<endl;
cout<<"candidate[i].name="<<candidate[i].name<<endl;
cout<<"candidate[check].name="<<candidate[i].name<<endl;
cout<<"candidate[i].party="<<candidate[i].party<<endl;
cout<<"candidate[check].party="<<candidate[check].party<<endl;
cout<<"candidate[i].age="<<candidate[i].age<<endl;
cout<<"candidate[check].age="<<candidate[i].age<<endl;
cin.clear();cin.sync();
do{
cout<<"|Enter the ears of experience in politics:";
cin>>candidate[i].xp;
}while((atoi(candidate[i].xp)<0)||(atoi(candidate[i].xp)>=atoi(candidate[i].age)));
cout<<"candidate[i].RegNomer="<<candidate[i].RegNomer<<endl;
cout<<"candidate[check].RegNomer="<<candidate[check].RegNomer<<endl;
cout<<"candidate[i].name="<<candidate[i].name<<endl;
cout<<"candidate[check].name="<<candidate[i].name<<endl;
cout<<"candidate[i].party="<<candidate[i].party<<endl;
cout<<"candidate[check].party="<<candidate[check].party<<endl;
cout<<"candidate[i].age="<<candidate[i].age<<endl;
cout<<"candidate[check].age="<<candidate[i].age<<endl;
cout<<"candidate[i].xp="<<candidate[i].xp<<endl;
cout<<"candidate[check].xp="<<candidate[check].xp<<endl;
cin.clear();cin.sync();
cout<<"|Enter the number of votes the candidate has:";
cin>>candidate[i].votes;
cout<<"candidate[i].RegNomer="<<candidate[i].RegNomer<<endl;
cout<<"candidate[check].RegNomer="<<candidate[check].RegNomer<<endl;
cout<<"candidate[i].name="<<candidate[i].name<<endl;
cout<<"candidate[check].name="<<candidate[i].name<<endl;
cout<<"candidate[i].party="<<candidate[i].party<<endl;
cout<<"candidate[check].party="<<candidate[check].party<<endl;
cout<<"candidate[i].age="<<candidate[i].age<<endl;
cout<<"candidate[check].age="<<candidate[i].age<<endl;
cout<<"candidate[i].xp="<<candidate[i].xp<<endl;
cout<<"candidate[check].xp="<<candidate[check].xp<<endl;
cout<<"candidate[i].votes="<<candidate[i].votes<<endl;
cout<<"candidate[check].votes="<<candidate[i].votes<<endl;
cin.clear();cin.sync();
}
system ("PAUSE");
}
return 0;
}
Hi guys,
Well basically I have a weird error that simply blows my mind away.I've asked friends but when even my IT teacher (i'm a student in high school) couldn't find the reason for this bug I decided to go and ask the other 3 billion people using the internet.Basically after every second entry of a string a concatenation is activated or something...i'm not even sure exactly how to explain it so here's my code.
This is just the part of the program where the entry is done.
All the extra couts i've put are there to track the progression of which the values of different the strings change for no apparent reason.Thank You all for you help!
P.S. also on a side note can any1 tell me how to delete intervals in a string ? I've thought of a way how with a cycle but i was wondering if there was a function or something.The think i'm aiming for is this:
From: 1 34 232 3 4
To get: 13423234
Thank You all again so much!