Very simple mathematic question
here comes for the most people a very simple question that I can't understand. How did I calculate the percent of a number?
If I have a variable with the number 1000 stored in it, and I want to calculate what 15,55 % of that number is and store the result in another variable. How? Can someone give me an example?
Re: Very simple mathematic question
This should help - http://www.purplemath.com/modules/percntof.htm
As far as code is concerned, what could you write?
Re: Very simple mathematic question
Re: Very simple mathematic question
shall I do something like this:
If we take 10 percent of 1000.
Code:
int result;
int number = 1000;
result = 10 % number;
I don't know if I shall use the % sign? Probably this is totaly wrong :D
Re: Very simple mathematic question
10 % of 1000 here would be 10*1000/100. % is for finding remainder.
Re: Very simple mathematic question
Quote:
Originally Posted by GCDEF
number times .1555
Can you explain this more? What is 'times'?
Re: Very simple mathematic question
Quote:
Originally Posted by exterminator
10 % of 1000 here would be 10*1000/100. % is for finding remainder.
Yes, but if I want 0.65% of 1000?
0.65*1000/65 is this correct?
Re: Very simple mathematic question
Quote:
Originally Posted by Lindberg
Can you explain this more? What is 'times'?
Hmm, no math knowledge, no language knowledge... ts ts ts :)
He means 1000 * 0.1555 :)
-Andy
Re: Very simple mathematic question
>> Yes, but if I want 0.65% of 1000?
>. 0.65*1000/65 is this correct?
No. It would be
Or more concisely
Re: Very simple mathematic question
ok, I have now came to a conclusion.
Code:
double result;
int number = 1000;
char chresult[15];
result = number * 0.15;
So simple it was :) Thanks for all help!
Re: Very simple mathematic question
Quote:
Originally Posted by Lindberg
here comes for the most people a very simple question that I can't understand. How did I calculate the percent of a number?
If I have a variable with the number 1000 stored in it, and I want to calculate what 15,55 % of that number is and store the result in another variable. How? Can someone give me an example?
No disrespect for Lindberg, who is asking an honest question, but this is a truly pathetic commentary on the school system in Sweden.
And I thought that the school system here in the U.S. was pathetic.
Re: Very simple mathematic question
Perhaps he is only 7 years old? :-)
Re: Very simple mathematic question
Quote:
Originally Posted by MikeAThon
And I thought that the school system here in the U.S. was pathetic.
Hmm... Are you sure you mean pathetic - or pathologic? ;)
Re: Very simple mathematic question
It's nothing wrong with the school system in sweden, i have learned the most mathematic thing in my school. But it is a quite different thing to calculate mathematics in a programming language like c++, especially if you are a beginner.
Quote:
Originally Posted by Mark Xa
Perhaps he is only 7 years old? :-)
I'm 30 years old :D