PDA

View Full Version : C++ question



jus71n742
May 17th, 2008, 05:40 AM
I am not sure what kind of loop I want to use for this but I am thinking a for or if statement.
what I am trying to do is for example I have an input of say 44 and for each 10 I give someone a point so an input of 44 is 4pts.
I would also like to figure out the flip side of that
say input is 4 is minus 1 so the input would result in -4 pts.

I have been reading but can't get a clear understanding of how to go about it

any assistance is greatly appreciated

amingv
May 17th, 2008, 05:56 AM
I don't see where the loop fits in; you could just use integer division (if you want to discard the rest):


int a = 44;
int b = 10
int points = a/b //gets assigned 4

Can you explain a little more, if that's not what you want to do?

jus71n742
May 17th, 2008, 06:04 AM
points is going to be a variable to keep a running total so in my other example 44 = 4 pts then the other was -4 pts then your total will be 0 ( they will all be added up later) I have points set up as a completely separate int. there will be a few more statements to input numbers I am just getting my pseudo code done right now

thadeoc
May 17th, 2008, 03:30 PM
if you mean that given an input value you want to add one point for each 10 in the input, and subtract one point for each 1 left over, try:


int input = 44;
int points = input / 10; //points is set to 4
input = input % 10; // input is set to 4
points -= input;