how can I get the remaining weight, without using the int modulus?
The problem is solving how many widgets are on the pallet, and inputs are the total weight and the pallet. In the program, ONEWIDGET is the weight of a widget.

since the input can put any random number, i want to inform the user if there is any unaccounted weight on the pallet and the amount. This value I thought to use % of the caluclations but the operation can't be done with doubles(variable and constant).

right now it's found by math: remaining= widgetWeight - (widgetNum*ONEWIDGET)

is thier a command for the ramander of un intergers?

Recommended Answers

All 5 Replies

well you can static cast your double variable to integer and get the remainder you want

working with decimals in dividing, if i disregard the decimals, won't it give a different answer?

well it depends..do u want to round off or do you want to get a certain number of decimal places...if you want to round off then you should use "ceil..more info here

on the other hand, if u want a more approximate value then you should use "set precision"..more info here

Try Something Like This.

First

Considering that your double is named x;

int absx=abs(x);
double remainder=x-absx;

then use the modulus operator with absx.
Something like

double answer=absx%some number;

Then Add in your remainder value

answer+=remainder;

So you wont loose your decimal points using this.

> This value I thought to use % of the caluclations but the operation can't be done with doubles(variable and constant).
You can use the fmod() function to find the remainder of division for floating values.

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.