formula for percent

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

percent

formula for percent

Post 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
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

Pay attention in class.
I have left this dump.
percent

Post by percent »

not helpful. can you please help me with it?
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post 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?
I have left this dump.
percent

Post by percent »

it's not homework, and I don't have any math teachers readily available
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post 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 "%"
Last edited by Patz QuickBASIC Creations on Wed Aug 31, 2005 5:32 pm, edited 1 time in total.
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post 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.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.
percent

Post 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
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post 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..
I have left this dump.
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post by Patz QuickBASIC Creations »

Z!re, tear him apart!
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post 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 "%" 
percent

Post 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?
percent

Post 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
Seb McClouth

Post by Seb McClouth »

PQBC, can I use your percent code (I will credit it), for whatever use?

grtz
Seb
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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...
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
someperson

Post by someperson »

Unbelieveable!! Persentage is so simple! Here is an example:

12 is to 156
%x is to %100

x=(100*12)/156
paulunknown
Coder
Posts: 17
Joined: Sat Aug 27, 2005 10:26 am

Post by paulunknown »

Hey, just curious, how old is everyone here?
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

WEll me I'm 37 :-)...probably the biggest number you'll get here LOL
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
Seb McClouth

Post by Seb McClouth »

23, and already 12 years in this business (not this site, but the programming that is.)

grtz
Seb McClouth

Post by Seb McClouth »

23, and already 12 years in this business (not this site, but the programming that is.)

grtz
Post Reply