hi!

ive compiled a program that gives me this error:
(88) : error C2296: '%' : illegal, left operand has type 'float'
(94) : error C2296: '%' : illegal, left operand has type 'float'
(100) : error C2296: '%' : illegal, left operand has type 'float'

thing is that i have all variables defined as float, and that shouldnt be a problem, right??

for (total_paquete1000 = 0; peso > 1000; total_paquete1000 ++)
	{
		if (dia == 7)
		{
			total_p_siguiente_prioritario_1000 += 1;
			[B]costo_p_siguiente_prioritario_1000 = costo_p_siguiente_prioritario + (((peso - 1000)%500)*2);[/B]
			cout << " Se le cobrarán: " << costo_p_siguiente_prioritario_1000 << " pesos";
		}
		else if (dia == 8)
		{
			total_p_siguiente_normal_1000 += 1;
			[B]costo_p_siguiente_normal_1000 = costo_p_siguiente_normal + (((peso - 1000)%500)*2);[/B]
			cout << " Se le cobrarán: " << costo_p_siguiente_normal_1000 << " pesos";
		}
		else if (dia == 9)
		{
			total_p_dos_dias_1000 += 1;
			[B]costo_p_dos_dias_1000 = costo_p_dos_dias_1000 + (((peso - 1000)%500)*2);[/B]			cout << " Se le cobrarán: " << costo_p_dos_dias_1000 << " pesos";
		}
	}

You can't do modulo on floats.

hi!

ive compiled a program that gives me this error:
(88) : error C2296: '%' : illegal, left operand has type 'float'
(94) : error C2296: '%' : illegal, left operand has type 'float'
(100) : error C2296: '%' : illegal, left operand has type 'float'

thing is that i have all variables defined as float, and that shouldnt be a problem, right??

for (total_paquete1000 = 0; peso > 1000; total_paquete1000 ++)
	{
		if (dia == 7)
		{
			total_p_siguiente_prioritario_1000 += 1;
			[B]costo_p_siguiente_prioritario_1000 = costo_p_siguiente_prioritario + (((peso - 1000)%500)*2);[/B]
			cout << " Se le cobrarán: " << costo_p_siguiente_prioritario_1000 << " pesos";
		}
		else if (dia == 8)
		{
			total_p_siguiente_normal_1000 += 1;
			[B]costo_p_siguiente_normal_1000 = costo_p_siguiente_normal + (((peso - 1000)%500)*2);[/B]
			cout << " Se le cobrarán: " << costo_p_siguiente_normal_1000 << " pesos";
		}
		else if (dia == 9)
		{
			total_p_dos_dias_1000 += 1;
			[B]costo_p_dos_dias_1000 = costo_p_dos_dias_1000 + (((peso - 1000)%500)*2);[/B]			cout << " Se le cobrarán: " << costo_p_dos_dias_1000 << " pesos";
		}
	}

FYI, the bold tags don't work with C++ style code tags. They DO work with non-specific code tags:

[code]

// paste code here. Can put bold highlighting.

[/code]

The C++ highlighting seems to override the manual bold text highlighting, so is not parsed as "bold tag", but is assumed to be part of the code itself. I see you are referring to lines 7, 13, and 19. Your problem is here:


((peso - 1000)%500)

If peso is a float, then peso - 1000 is a float. The mod operator is looking for an integer on the left and the right of the % operator.

If you are looking for a remainder and peso needs to be a float, consider fmod from cmath.

http://www.cplusplus.com/reference/clibrary/cmath/fmod.html

thanks!
i've fixed it!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.