Error C2296

New to programming, can't manage to fix this error

Page 1 of 1

4 Replies - 5654 Views - Last Post: 12 October 2008 - 09:55 AM Rate Topic: -----

#1 Covalent  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,661
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 Covalent  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#4 dan_ram  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • 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)
Was This Post Helpful? 0
  • +
  • -

#5 Covalent  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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++;
	}
}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1