Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old October 16th, 2004, 11:02 PM
Dodot Dodot is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 Dodot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Help!!Check my VB program and tell me what I'm doing wrong!!

Tell me the right way to do it!!!!! I'm having problems with this questions
The world population reached 6 billion people in 1999 and was growing at the rate of 1.4 percent each year.
Assuming that the population will continue to grow at the asme rate, write a program to determine when
the population will exceed 10 billion.

What am I doing wrong??
Private Sub cmdbutton_Click()
Dim population As Integer
Dim years As Integer
years = 0
population = 6000000
Do While population > 10000000
population = population * 0.014
years = years + 1
Loop
picWhen.Print "In"; years; "Population will be"; population;
End Sub

Last edited by Dodot : October 17th, 2004 at 12:26 PM. Reason: I need answers

Reply With Quote
  #2  
Old October 17th, 2004, 01:01 AM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 18 h 33 m 48 sec
Reputation Power: 180
Your first problem is using an integer datatype, which doesn't count to the billions. Review the available VB datatypes in the documentation.

Your next problem is not posting the error you got when you tried to run your code.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old October 20th, 2004, 06:34 PM
danielgraham danielgraham is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 6 danielgraham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by Dodot
Tell me the right way to do it!!!!! I'm having problems with this questions
The world population reached 6 billion people in 1999 and was growing at the rate of 1.4 percent each year.
Assuming that the population will continue to grow at the asme rate, write a program to determine when
the population will exceed 10 billion.

What am I doing wrong??
Private Sub cmdbutton_Click()
Dim population As Integer
Dim years As Integer
years = 0
population = 6000000
Do While population > 10000000
population = population * 0.014
years = years + 1
Loop
picWhen.Print "In"; years; "Population will be"; population;
End Sub


Try changing


Code:
 
Private Sub cmdbutton_Click()
Dim population As long
Dim years As Integer
years = 0
population = 6000000
Do While population > 10000000
population = population * 0.014
years = years + 1
Loop
picWhen.Print "In"; years; "Population will be"; population;
End Sub
 
 

Reply With Quote
  #4  
Old October 21st, 2004, 08:49 PM
Rich's Avatar
Rich Rich is offline
Administrator
Developer Shed Admin.
 
Join Date: Sep 2003
Location: Fort Lauderdale, FL
Posts: 151 Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level)Rich User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 11 h 37 sec
Reputation Power: 10
The code inside the while will never be executed. You are saying:

population = 6 million

Then saying:

do while population > 10 million

The do loop will NEVER execute, and your code will just say "in 0 years, the population will be 6 million"

(Note, Im using the word "million" for clarity)


What you WANT the do loop to say, is:

do while population < 10 million...



Thats the SERIOUS logic flaw I see...

Reply With Quote
  #5  
Old October 22nd, 2004, 06:01 AM
Leslie's Avatar
Leslie Leslie is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Honolulu
Posts: 184 Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 29 m 2 sec
Reputation Power: 8
You are multiplying by ZERO .014. your have created an ever-shrinking population count, at this rate we will be extinct in no time and your loop will NEVER END. That statement makes population = 1.4 percent of it's original population. 1 % of 100 is 1 so that is a pretty small number.

Change to this:
population = population * 1.014

like it said in the problem "rate of 1.4 percent" . Rule: move the decimal two places to the left. If you are DECREASING to the value leave the zeros. If you are INCREASING by the value you have to represent the EXISTING value with a 1 to the left of the decimal because we all know that 1 x 1 is 1. You have to have at LEAST that if you are going to increase a value.


It would do you some good in solving these to understand how to set a b... reakpoint and step through your code one line at a time and WATCH the values. If you don't understand it, you need to get help from your teacher because this is fundamental to any programming. In VB You can wave your mouse over a variable after you execute a step and see for yourself what is happening to your values. YOu can watch it Do ...Loop and see why it isn't looping.

Open the Immediate window and add debug.print to your program like this:

Do While population < 10000000
population = population * 0.014
years = years + 1
Debug.Print population
Loop

run it and look at your immediate window. Again, get a demonstration from someone who knows. It can be hard to grasp the meaning of "debug" and "immediate" and "step the code" when you are first starting but you have to understand it if you want to be able to succeed at this so if you don't get it, keep asking "what do you mean?" and don't be afraid to say "show me" ... good luck and hang in there.

Reply With Quote
  #6  
Old October 22nd, 2004, 07:33 AM
Leslie's Avatar
Leslie Leslie is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Honolulu
Posts: 184 Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level)Leslie User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 20 h 29 m 2 sec
Reputation Power: 8
Clarification on dealing with percents

population grows by 1.4 percent:
population = population * 1.014

population shrinks by 1.4 percent:
population = population - (population * 0.014)

population shrints TO 1.4 percent:
population = population * 0.014

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Help!!Check my VB program and tell me what I'm doing wrong!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway