# Error C2296

Page 1 of 1

## 4 Replies - 7180 Views - Last Post: 12 October 2008 - 09:55 AMRate 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=67269&amp;s=09f275b71767e162d0457aaf33088a11&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Covalent

Reputation: 0
• Posts: 39
• Joined: 12-October 08

# Error C2296

Posted 12 October 2008 - 09:12 AM

Hi everyone!

I'm all new to programming and in one of my course, we got some algorithm to do and I tried to program it in C to see if it was working. So here's what I've done.
```#include <stdio.h>

int main()
{
int w,x,y,z;
float i,somme,reste;

while (i<10000);
{
w=(i%1000);
reste=i/1000;
x=reste%100;
reste=reste/100;
y=reste%10;
reste=reste/10;
z=reste;

while(somme<i);
{
somme=w+x+y+z;
w=x;
x=y;
y=z;
z=somme;
}
if (somme==i);
{
printf("%f\n", somme);
}
i++;
}
}
```

The goal of it is to find every 4 digit numbers that when you sum up the digits, you gotta find that number in it. Anways!

For some reason I just can't find how to fix this error :

```(10) : error C2296: '%' : illegal, left operand has type 'float'
(12) : error C2296: '%' : illegal, left operand has type 'float'
(14) : error C2296: '%' : illegal, left operand has type 'float'
```

Any way to fix it?

Is This A Good Question/Topic? 0

## Replies To: Error C2296

• Saucy!

Reputation: 6246
• Posts: 24,014
• Joined: 23-August 08

## Re: Error C2296

Posted 12 October 2008 - 09:13 AM

Change your variables' type to int from float. You don't need to use decimals (I assume), and you can't use the modulus operator (%) with a float.

### #3 Covalent

Reputation: 0
• Posts: 39
• Joined: 12-October 08

## Re: Error C2296

Posted 12 October 2008 - 09:15 AM

Nevermind! I just realised that I don't even need float since all my numbers can't have fractions. Thanks anyway!

This post has been edited by Covalent: 12 October 2008 - 09:18 AM

### #4 dan_ram

Reputation: 5
• Posts: 141
• Joined: 15-August 07

## Re: Error C2296

Posted 12 October 2008 - 09:22 AM

try reste= i/1000.0
im not sure if the steps like x=reste%100 will work...as you are trying to find the remainder of a float(non- whole number) ( doesnt make sense)

### #5 Covalent

Reputation: 0
• Posts: 39
• Joined: 12-October 08

## Re: Error C2296

Posted 12 October 2008 - 09:55 AM

Ok so I solved my problem. But for some reason, when I debug it, it just doesn't do anything, or it takes very long. Anything is wrong there?

```#include <stdio.h>

int main()
{
int w,x,y,z,i,somme,reste;
i=1000;
somme=w=x=y=z=reste=0;

while (i<10000);
{
w=i/1000;
reste=i%1000;
x=reste/100;
reste=reste%100;
y=reste/10;
reste=reste%10;
z=reste;

while(somme<i);
{
somme=w+x+y+z;
w=x;
x=y;
y=z;
z=somme;
}
if (somme==i);
{
printf("%f\n", somme);
}
i++;
}
}
```