Click here to Skip to main content
11,486,023 members (74,605 online)
Rate this: bad
good
Please Sign up or sign in to vote.
Given a Scenario where i need to calculate the loss percentage in weight where the issued weight is in kg and grams and the received weight is also in kg and grams. so the scenario becomes 4 text boxes and a button and an extra text box to display the loss percentage. Can anyone please help me with this? Also the grams need to be converted into kg. I have tried it but whenever the grams is 000,it throws an error.
Posted 5-Oct-12 0:42am
Comments
_Amy at 5-Oct-12 5:44am
   
Where is your code? Where you are getting error? Look, this is just a homework and we are not having your HDD so that we'll solve your problem. While posting your question try to post the dummy codes also.
   
I transported myself to your place using tele-portation and checked your code. It seems there is issue in the code which needs to be fixed. After that it will not throw the error..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

But your specific problem is simple:
"whenever the grams is 000,it throws an error."It will - division by zero generates a result that can't be stroed in a computer, so it generates a "devision by zero" exception. So check first:
double kilos = 0.0;
if (grams != 0)
   {
   kilos = grams / 1000;
   }
  Permalink  
Comments
CPallini at 5-Oct-12 5:50am
   
Hey man, where is the division BY zero? :-D
OriginalGriff at 5-Oct-12 5:52am
   
I'm just guessing he doesn't know how divide works either! :O

(Phew, I think I got away with that...)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You need to convert the pairs {kg,g} into total g (simpler than converting to total kg) and then apply the percent formula (e.g. 100 * (issued-received) / issued), being sure that divisor is greater than zero (as it, in any case but wrong input, should be).
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 C#developer.asp 429
1 Sergey Alexandrovich Kryukov 375
2 Maciej Los 365
3 Mehdi Gholam 250
4 OriginalGriff 144
0 Sergey Alexandrovich Kryukov 8,819
1 OriginalGriff 8,047
2 Sascha Lefèvre 3,199
3 Maciej Los 2,886
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 5 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100