Substring Operations Produce Odd Error - Please Help!
I've got an assignment due Monday, and I've gotten the program down to one tiny error, and it's cosmetic at best. However, I'd like to have the assignment done to the letter just in case.
In the block below, the program is supposed to force the output to only two decimal places by converting the double value side3 into a string, and rearranging it using substrings until the output is formatted exactly the way I want it to be.
The problem, however, lies in the fact that when posDec is ".00", I'd like the program to erase it and thus append nothing to preDec, producing an output with no decimals at all. I've tried "if" and "when" statements, but each time I only get the error "Cannot convert &posDec. Conversion Error."
{ int dec, sign; char *buff;
buff = _fcvt(side3, 2, &dec, &sign);
string dump = buff; int dSize = dump.size() - 1;
string preDec = dump.substr(0, dec);
string posDec = "." + dump.substr(dec, dSize);
// if (posDec = ".00") posDec.erase();
string s3fin = preDec + posDec;
cout<<"\nSide 3 = "<<s3fin<<" units."<<endl;
}
I am using Bloodshed Dev C++ 9 Beta. Again, any help would be greatly appreciated, and many thanks in advance.
- M. Jackson
[1373 byte] By [
mjacks33] at [2007-11-19 18:28:26]

# 2 Re: Substring Operations Produce Odd Error - Please Help!
Is this the line that triggers the error?
if (posDec = ".00") posDec.erase();
It should be
if (posDec == ".00") posDec.erase();
but I don't see the connection with the error message.
Wow. That... That is just... Wow. Ya know, sometimes I wonder if I should try and fit some breaks into my twenty-four hour programming sprees. I mean, I thought I might be making some noob-ish mistake, but I've got to say that takes the cake.
I any case, thanks a million!
# 4 Re: Substring Operations Produce Odd Error - Please Help!
I am using Bloodshed Dev C++ 9 Beta. Again, any help would be greatly appreciated, and many thanks in advance.
Dev C++ is based on MinGW, which uses a GCC compiler.
GCC can automatically diagnose this type of assignment error, reporting a warning message.
I recommend that you use in all your programs these compiler options:
"-Wall --pedantic"
It'll detect many constructs potentially hiding errors and non-ISO compliant constructs.
# 5 Re: Substring Operations Produce Odd Error - Please Help!
Dev C++ is based on MinGW, which uses a GCC compiler.
GCC can automatically diagnose this type of assignment error, reporting a warning message.
I recommend that you use in all your programs these compiler options:
"-Wall --pedantic"
It'll detect many constructs potentially hiding errors and non-ISO compliant constructs.
Ah, many thanks for that one.