need help + good compiler?

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
zero_cool
New poster
Posts: 27
Joined: Fri Sep 02, 2005 6:33 am

need help + good compiler?

Post by zero_cool » Wed Oct 19, 2005 4:44 am

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;
}
}
_____________________________________________________________

intergalactic
New poster
Posts: 2
Joined: Fri Nov 11, 2005 7:20 pm

A good c++ compiler

Post by intergalactic » Fri Nov 11, 2005 7:23 pm

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)

zero_cool
New poster
Posts: 27
Joined: Fri Sep 02, 2005 6:33 am

Post by zero_cool » Sat Jan 21, 2006 5:29 pm

thx for your suggestion. btw, I've fixed my program thx to you.

Post Reply

Return to “C++”