# too many numbers that i dont want

Page 1 of 1

## 2 Replies - 812 Views - Last Post: 07 November 2009 - 06:46 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=137388&amp;s=a060c08572d67b7ad94d35683173e20e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ninreznorgirl2

Reputation: 0
• Posts: 57
• Joined: 26-April 09

# too many numbers that i dont want

Posted 07 November 2009 - 05:06 PM

i am overloading the assignment operator. the problem i am having is that it is printing more numbers then what it is supposed to. i know what the problem is, but i dont know how to fix it. the k is incremented in the beginning, and so its printing the extra numbers that k has stored in it. any ideas about how to go around this problem?? it is supposed to be printing 0.123 if that is the number entered but its printing 0.-52 -52123

help??

``` MyFloat& MyFloat::operator= (const char RightSide[])
{
int k = 0;

NumberOfDigits = 0;

if ((RightSide[k] != '0' && RightSide[k] != '.'))
return *this;

while( RightSide[k] == '0' ||  isspace(RightSide[k]))
k++;

if (RightSide[k] != '.')
return *this;
k++;

while(isdigit(RightSide[k]) && k < RightSide[k])
{
Number[k] = RightSide[k] - '0';
k++;
}

NumberOfDigits = k;

for(k; k < MAX_DIGITS; k++)	//insert an end buffer of zeros
Number[k] = 0;

return *this;
}
```

this is where the overloaded operator is being tested:
```void TestAssignment()
{
MyFloat X;
char	X_Str[100];

cout << "\n------------  Testing \"=\" for MyFloat --------------------\n";
do
{
cout << "\nEnter string holding float: ";

cin.getline(X_Str, 100);

X = X_Str;  // Call MyFloat = operator

if ( X.Digits() == 0 )	   //  Error in string format
cout << "\nFormat error! ";

cout << "\nAfter assignment,	 'X = "<< X << "'" << endl;
}
while ( SpaceBarToContinue() );
}

```

Is This A Good Question/Topic? 0

## Replies To: too many numbers that i dont want

### #2 redhotfire0

Reputation: 10
• Posts: 210
• Joined: 13-July 09

## Re: too many numbers that i dont want

Posted 07 November 2009 - 06:37 PM

```MyFloat& MyFloat::operator= (const char RightSide[])
// what is the equal sign for, its a function, not a equation

```

I could be wrong.

This post has been edited by redhotfire0: 07 November 2009 - 06:38 PM

### #3 ninreznorgirl2

Reputation: 0
• Posts: 57
• Joined: 26-April 09

## Re: too many numbers that i dont want

Posted 07 November 2009 - 06:46 PM