error C2296
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;
<strong>costo_p_siguiente_prioritario_1000 = costo_p_siguiente_prioritario + (((peso - 1000)%500)*2);</strong>
cout << " Se le cobrarán: " << costo_p_siguiente_prioritario_1000 << " pesos";
}
else if (dia == 8)
{
total_p_siguiente_normal_1000 += 1;
<strong>costo_p_siguiente_normal_1000 = costo_p_siguiente_normal + (((peso - 1000)%500)*2);</strong>
cout << " Se le cobrarán: " << costo_p_siguiente_normal_1000 << " pesos";
}
else if (dia == 9)
{
total_p_dos_dias_1000 += 1;
<strong>costo_p_dos_dias_1000 = costo_p_dos_dias_1000 + (((peso - 1000)%500)*2);</strong> cout << " Se le cobrarán: " << costo_p_dos_dias_1000 << " pesos";
}
}
gispe
Junior Poster in Training
74 posts since Jul 2008
Reputation Points: 6
Solved Threads: 0
You can't do modulo on floats.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
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;
<strong>costo_p_siguiente_prioritario_1000 = costo_p_siguiente_prioritario + (((peso - 1000)%500)*2);</strong>
cout << " Se le cobrarán: " << costo_p_siguiente_prioritario_1000 << " pesos";
}
else if (dia == 8)
{
total_p_siguiente_normal_1000 += 1;
<strong>costo_p_siguiente_normal_1000 = costo_p_siguiente_normal + (((peso - 1000)%500)*2);</strong>
cout << " Se le cobrarán: " << costo_p_siguiente_normal_1000 << " pesos";
}
else if (dia == 9)
{
total_p_dos_dias_1000 += 1;
<strong>costo_p_dos_dias_1000 = costo_p_dos_dias_1000 + (((peso - 1000)%500)*2);</strong> 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 [b] 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
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
gispe
Junior Poster in Training
74 posts since Jul 2008
Reputation Points: 6
Solved Threads: 0