Page 1 of 2

formula for percent

Posted: Wed Aug 31, 2005 1:36 pm
by percent
I'm writing a program, and I need it to calculate the percent of two numbers entered. First, the teacher enters the number of registered students (student) and then the number of absent students (absent)

once these two numbers are inputed, what formula would I use to find the percent of absent students. For example, there are 345 students registered, and 4 are absent. what QB formula would I use in QB to tell me the percentage of students absent?

From what I can remember about percents wouldn't it be:
LET percent = absent / student

the answer doesn't come out correclty though. If somebody could shed some light on this topic it would be greatly appreciated

Posted: Wed Aug 31, 2005 1:59 pm
by Z!re
Pay attention in class.

Posted: Wed Aug 31, 2005 2:05 pm
by percent
not helpful. can you please help me with it?

Posted: Wed Aug 31, 2005 2:08 pm
by Z!re
It is generally considered somewhat of a rule, not to help people with their homework.

Besides, as it's only the percent formulae, maybe you should ask your math teacher?

Posted: Wed Aug 31, 2005 2:11 pm
by percent
it's not homework, and I don't have any math teachers readily available

Posted: Wed Aug 31, 2005 2:21 pm
by Patz QuickBASIC Creations
Try this. Tell me if it doesn't fit your needs, or doesn't work at all. I don't have any version of QB or FB where I'm at.

Code: Select all

' PQBC Percent Program
Input "Number to take percentage of? ", num1
Input "Percent to take? ", num2
Let percent = val(left$(str$(num1 / num2) * 100),10)
Print percent "%"

Posted: Wed Aug 31, 2005 2:28 pm
by moneo
percent wrote:it's not homework, and I don't have any math teachers readily available
As a rule, we don't help people with homework, like Z!re said. It sounds like homework to Z!re and to me too. If it's not homework, then what is it? Explain, and we'll help you.
*****

Posted: Wed Aug 31, 2005 3:14 pm
by percent
PQBC, that's what I had to begin with, but I keep getting an Overflow error. The calculation you gave me is in a subprogram and is being called to the main program, might that have something to do with the overflow?

Z!re, it's a practice assignment from my computer programming class. It isn't being submitted for a grade. The whole purpose of the assignment is to build a program using subprograms and CALL statements only. I have the formula down, but I keep getting an overflow error

Posted: Wed Aug 31, 2005 3:22 pm
by Z!re
Pay attention in class...

Really.. you should..


Or you could always ask your teacher about it..

Overflow is casued by a division by zero, which is caused by you using subs without knowing how to use them properly. most likely due to not paying attention in class..

Posted: Wed Aug 31, 2005 3:40 pm
by Patz QuickBASIC Creations
Z!re, tear him apart!

Posted: Wed Aug 31, 2005 5:33 pm
by Patz QuickBASIC Creations
Fixed, i think. Overflow won't occur with revised version.

Code: Select all

' PQBC Percent Program 
Input "Number to take percentage of? ", num1 
Input "Percent to take? ", num2 
Let percent = val(left$(str$(num1 / num2) * 100),10) 
Print percent "%" 

Posted: Thu Sep 01, 2005 7:12 am
by percent
still getting an error with it. When I try to run it I get an Expected: , error
when the error appears it highlights the ),10) part of the program.

If I upload the BAS file could somebody possibly take a look at it for me?

Posted: Thu Sep 01, 2005 8:24 am
by percent
figured it out, thanks for the help PQBC
It turn sout it had nothing to do with the LET statements. I wasn't passing all of the necessary parameters to and from the SUBs. Everything seems to be working now

Posted: Thu Sep 01, 2005 9:47 am
by Seb McClouth
PQBC, can I use your percent code (I will credit it), for whatever use?

grtz
Seb

Posted: Thu Sep 01, 2005 10:45 am
by Rattrapmax6
You know.. you could have avoided the homework battle by not putting code... seems all he needed was the formula:

Persent = ValueForPersent / WholeNumber * 100

50% = 25 / 50 * 100

:P Which by far might have been in the math class, not the coding class...

Posted: Thu Sep 01, 2005 8:14 pm
by someperson
Unbelieveable!! Persentage is so simple! Here is an example:

12 is to 156
%x is to %100

x=(100*12)/156

Posted: Thu Sep 01, 2005 8:30 pm
by paulunknown
Hey, just curious, how old is everyone here?

Posted: Thu Sep 01, 2005 8:50 pm
by MystikShadows
WEll me I'm 37 :-)...probably the biggest number you'll get here LOL

Posted: Fri Sep 02, 2005 7:11 am
by Seb McClouth
23, and already 12 years in this business (not this site, but the programming that is.)

grtz

Posted: Fri Sep 02, 2005 7:11 am
by Seb McClouth
23, and already 12 years in this business (not this site, but the programming that is.)

grtz