•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,013 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,596 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 239 | Replies: 3
![]() |
•
•
Join Date: Jul 2008
Posts: 47
Reputation:
Rep Power: 0
Solved Threads: 0
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??
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??
cplusplus Syntax (Toggle Plain Text)
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
Join Date: Jan 2008
Posts: 1,771
Reputation:
Rep Power: 8
Solved Threads: 218
•
•
•
•
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??
cplusplus Syntax (Toggle Plain Text)
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 [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/c...math/fmod.html
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Fanciful errors :o (C)
- how to correct errors (C)
- C++ problem (C++)
Other Threads in the C++ Forum
- Previous Thread: Dynamic 2d array of CString
- Next Thread: c++ game help



Linear Mode