Can somebody help me with my program. My program run normally in my compiler but it said compile error. Is there any suggestion to what compiler should I use? Right now I use visual c++ 6.0.
This is my code
_____________________________________________________________
#include <iostream>
#include <string>
using namespace std;
//swap two character
void Swap(char &a,char &b) {
char temp;
temp=a;
a=b;
b=temp;
};
//Cek whether a string is a palindrome or not
int CekPal(string str) {
long i,max;
int bol;
bol=1;
max=str.length()/2;
for (i=0;i<max;i++) {
if (str!=str[str.length()-1-i]) {
bol=0;
break;
}
}
return bol;
};
//to reverse a string
string RevString(string str) {
long i,max;
max=str.length()/2;
for (i=0;i<max;i++) {
swap(str,str[str.length()-1-i]);
}
return str;
};
void main() {
long i,j,tc,ct,keep;
string st,tmp;
cin >> tc;
getline(cin,st);
for (i=0;i<tc;i++) {
getline(cin,st);
ct=0;
while (CekPal(st)==0) {
ct++;
tmp=RevString(st);
keep=0;
for (j=st.length()-1;j>=0;j--) {
st[j]=st[j]+tmp[j]+keep-'0';
if (st[j]>'9') {
keep=1;
st[j]=st[j]-10;
}
else
keep=0;
}
if (keep==1) {
st='1'+st;
}
}
cout << ct << ' ' << st << endl;
}
}
_____________________________________________________________
need help + good compiler?
Moderator: Board moderators
-
- New poster
- Posts: 2
- Joined: Fri Nov 11, 2005 7:20 pm
A good c++ compiler
The best and simplest compiler to program in Windows is Dev-C++, i recommend you to look for it in Google, i compiled your program witout any errors, only change
void main()
by
int main()
and i think that when you use swap you meant Swap (it compiled because actually there exists a STL function named swap)
void main()
by
int main()
and i think that when you use swap you meant Swap (it compiled because actually there exists a STL function named swap)