User Name Password Register
DaniWeb IT Discussion Community
All
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,810 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,894 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: 244 | Replies: 3
Reply
Join Date: Jul 2008
Posts: 47
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

error C2296

  #1  
Jul 24th, 2008
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??

  1.  
  2. for (total_paquete1000 = 0; peso > 1000; total_paquete1000 ++)
  3. {
  4. if (dia == 7)
  5. {
  6. total_p_siguiente_prioritario_1000 += 1;
  7. [b]costo_p_siguiente_prioritario_1000 = costo_p_siguiente_prioritario + (((peso - 1000)%500)*2);[/b]
  8. cout << " Se le cobrarán: " << costo_p_siguiente_prioritario_1000 << " pesos";
  9. }
  10. else if (dia == 8)
  11. {
  12. total_p_siguiente_normal_1000 += 1;
  13. [b]costo_p_siguiente_normal_1000 = costo_p_siguiente_normal + (((peso - 1000)%500)*2);[/b]
  14. cout << " Se le cobrarán: " << costo_p_siguiente_normal_1000 << " pesos";
  15. }
  16. else if (dia == 9)
  17. {
  18. total_p_dos_dias_1000 += 1;
  19. [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";
  20. }
  21. }
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 3,638
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 22
Solved Threads: 418
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: error C2296

  #2  
Jul 24th, 2008
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.
Reply With Quote  
Join Date: Jan 2008
Posts: 1,771
Reputation: VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice VernonDozier is just really nice 
Rep Power: 8
Solved Threads: 218
VernonDozier VernonDozier is offline Offline
Posting Virtuoso

Re: error C2296

  #3  
Jul 24th, 2008
Originally Posted by gispe View Post
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??

  1.  
  2. for (total_paquete1000 = 0; peso > 1000; total_paquete1000 ++)
  3. {
  4. if (dia == 7)
  5. {
  6. total_p_siguiente_prioritario_1000 += 1;
  7. [b]costo_p_siguiente_prioritario_1000 = costo_p_siguiente_prioritario + (((peso - 1000)%500)*2);[/b]
  8. cout << " Se le cobrarán: " << costo_p_siguiente_prioritario_1000 << " pesos";
  9. }
  10. else if (dia == 8)
  11. {
  12. total_p_siguiente_normal_1000 += 1;
  13. [b]costo_p_siguiente_normal_1000 = costo_p_siguiente_normal + (((peso - 1000)%500)*2);[/b]
  14. cout << " Se le cobrarán: " << costo_p_siguiente_normal_1000 << " pesos";
  15. }
  16. else if (dia == 9)
  17. {
  18. total_p_dos_dias_1000 += 1;
  19. [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";
  20. }
  21. }



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
Reply With Quote  
Join Date: Jul 2008
Posts: 47
Reputation: gispe is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
gispe gispe is offline Offline
Light Poster

Re: error C2296

  #4  
Jul 24th, 2008
thanks!
i've fixed it!!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 7:58 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC