Go Back   Tech Support Forum > The IT Pro > Programming

Visual logic While Loop Question

This is a discussion on Visual logic While Loop Question within the Programming forums, part of the Tech Support Forum category. I'm working on a calorie counting program for a class project. We created 3 different methods of calculating "calories burned."


Reply
 
Thread Tools Search this Thread
Old 03-13-2012, 04:11 PM   #1
Registered Member
 
Join Date: Mar 2012
Posts: 5
OS: Win 7 Home Premium SP1



I'm working on a calorie counting program for a class project. We created 3 different methods of calculating "calories burned." We used a while loop to loop back through the input functions so the user can input more than 1 kind of activity for burning calories. The problem is, we can't get the "calories burned" totals to filter down to the next calculation module in the program. It appears to me that every time the module makes a loop, it's loses the data it just calculated. So by time it exits, there is no "calories burned" information to pass to the next module.

I am in week #4 of my very first programming class and I have absolutely no idea how to fix this! I am going to upload a word doc with the "Input" module flowchart. If anyone out there can help me crack the code on this one (pun intended!) I will be forever in your debt.
Attached Files
File Type: doc Input Flowchart.doc (80.5 KB, 282 views)

__________________
Rick_In_Tampa is offline   Reply With Quote
Old 03-13-2012, 05:48 PM   #2
Games Team | Tech
 
Special2God's Avatar
 
Join Date: Oct 2009
Location: Earth
Posts: 4,317
OS: Win 7 (x64)

My System


You flow chart looks fine.
Make sure that the calorie total variable is declared outside the loop and make sure that the loop never resets the calorie total, i.e.
This is simply pseudo code, and is not for any specific programing language.
Code:
var total = 0;
while(something == somethingElse) {
total = total + additionalCalories;
print("Adding " + addotionalCalories + " calories");
}
print("You burned" + total + " total calories");
This appears to be what your flowchart already does.
I would suggest printing the calorie total at the beginning or end of the loop to discover whether your total is being properly carried over after each loop.

__________________
Special2God is offline   Reply With Quote
Old 03-14-2012, 04:16 AM   #3
Registered Member
 
Join Date: Mar 2012
Posts: 5
OS: Win 7 Home Premium SP1



Thanks for the quick response!!

I think we have what you are escribing already in the program. I am attaching another Word doc that shows the high level flowchart and then the individual calculation modules.

Like I said... This is only my 4th week doing this stuff and I have no clue why this won't work. But I do appreciate your help!!!

Rick


Quote:
Originally Posted by Special2God View Post
You flow chart looks fine.
Make sure that the calorie total variable is declared outside the loop and make sure that the loop never resets the calorie total, i.e.
This is simply pseudo code, and is not for any specific programing language.
Code:
var total = 0;
while(something == somethingElse) {
total = total + additionalCalories;
print("Adding " + addotionalCalories + " calories");
}
print("You burned" + total + " total calories");
This appears to be what your flowchart already does.
I would suggest printing the calorie total at the beginning or end of the loop to discover whether your total is being properly carried over after each loop.
Attached Files
File Type: doc Calc Modules.doc (91.5 KB, 128 views)
__________________
Rick_In_Tampa is offline   Reply With Quote
Old 03-14-2012, 07:44 AM   #4
Games Team | Tech
 
Special2God's Avatar
 
Join Date: Oct 2009
Location: Earth
Posts: 4,317
OS: Win 7 (x64)

My System


I'm not sure what might be wrong.
Some of the variable names in your flow chart are ambiguous and appear in some of the modules, but not in others, so without actually seeing some of the code I can't be sure where the error might be located.

If you could provide some code that would be appreciated, remember to surround code with code tags
HTML Code:
[CODE][/CODE]
I'll be happy to look over the code for any logic errors, remember that TSF does not write your code for you.
Especially for educational assignments, we prefer to help you identify your problem and give you a chance to solve it on your own.
The programing language does not matter; there are enough helpers around the programing forum that someone will know the language
__________________
Special2God is offline   Reply With Quote
Old 03-15-2012, 10:43 AM   #5
Windows Tech Team
 
Join Date: Jul 2010
Location: SA
Posts: 1,911
OS: DOS 3.3



Hi

You need to use arguments with your procedures so that the variable values are passed between your procedures.
In other words you need an argument variable (in your main program) when calling the "Input Data" procedure. This can then pass the aeroTotal value to your "Input Data" procedure. When the "Input Data" procedure ends it can then transfer the value back to the main procedure for the use in the "Output Results" procedure.
The same logic would be used when calling the "aeroCalc" and "runningCalc" procedures from the "Input Data" Procedure

Also at the end of the while loop in the "Input Data" procedure you would need to have an assignment box (?) that adds the calories.

Something like this in pseudocode:
Code:
Main
  calBurn = 0
  InputData(calBurn)
End Main

InputData(CalsVar)
  c = CalsVar
  while more <= 3
    ....
    aeroCalc(c)   
    CalsVar = CalsVar + c
  end While
End InputData

aeroCalc(cVar)
  ...
  cVar = aeroTotal
end aeroCalc
Hope this makes sense. Also as Special2God says many of your variable names are ambiguous. Each procedure should have a unique set of variable names.
__________________
AlbertMC2 is offline   Reply With Quote
Old 04-26-2013, 06:31 PM   #6
Registered Member
 
Join Date: Apr 2013
Posts: 1
OS: windows 7



Quote:
Originally Posted by Rick_In_Tampa View Post
Thanks for the quick response!!

I think we have what you are escribing already in the program. I am attaching another Word doc that shows the high level flowchart and then the individual calculation modules.

Like I said... This is only my 4th week doing this stuff and I have no clue why this won't work. But I do appreciate your help!!!

Rick
I am having so much trouble doing the (While?) Loop in Visual Logic, and I'm trying to do this question:
Please Try Again. Write a program that asks the user to respond to a question by entering
either 1 for yes or 2 for no. Use a While loop to continue prompting the user until a valid
response is entered. Upon entering a valid response, the program should display an appropriate message to the user.


Can you help with the flowchart and code for this While Loop? I can send you my VL file and Word document.....

my email is {email address removed}
__________________
jhmkmacoolcs is offline   Reply With Quote
Old 04-27-2013, 11:48 AM   #7
Games Team | Tech
 
Special2God's Avatar
 
Join Date: Oct 2009
Location: Earth
Posts: 4,317
OS: Win 7 (x64)

My System


First of all, welcome to TSF.
Please do not reopen old threads, start a new one if you have a new question.
If you have a question please use the forums instead of your email, we all want to learn from each other and communicating by email does not allow other people to contribute their advice and learn from each other.

Secondly, I'm not sure if I understand your question, but the flow chart would by very simple.
First the user's input is a simple generic action (normally represented by a box shape in flowcharts).
A line connects this first box to the next shape.
Then there is a decision based on the user's input (normally represented by a diamond shape in most flowcharts).
Two lines leave the decision diamond representing true or false outcomes to the decisions.
If the user's input is 1, then a line goes from the decision diamond to another box that represents displaying the appropriate response message.
If the user's input is 2, then a line goes from the decision diamond and makes a loop and goes back to the user input box shape to represent the user's need to re-enter a valid input.

Add necessary labels to the boxes and lines in the flowchart and double check the flowchart logic by creating a mental scenario for a user who enters 1 or 2 and follow the lines in the flowchart to see if the outcome of each choice is correct.

__________________
Special2God is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Computer in Reboot Loop
I custom built my computer just a little over a year ago and yesterday it randomly turned off while playing Civ 5 with some friends. It then attempted to reboot and then shut itself off and then rebooted in a continuous loop. My roommate is a CS major and we opened up the computer and tested other...
drabideau08 RAM and Power Supply Support 4 03-15-2012 10:36 AM
Any communications cable experts in here? Question about tracer wire.
I have a four conductor shielded cable that I have a question about. Basically the device I am using this cable with has five prongs it. Data "Tx + and -", data "Rx + and -", and "shield". Well the wire I am using has a fifth cable in it. But it’s not made out of copper, I think it may be steel...
audiobahn1000 Cabling and Network Cards 1 03-14-2012 10:54 AM
System sleeps/hibernates after a while?
Hey everyone, A few weeks ago, I updated to Windows 7 Ultimate 64-bit, and now when I leave my computer on to download something, after a while (I'm not sure how long) the computer automatically sleeps. It is a PC, not a laptop. I never had this problem until I installed W7
navneeta1 Windows 7 Support, Windows Vista Support 1 03-13-2012 08:36 AM

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

BB code is on
Smilies are on
[IMG] code is on
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Post a Question


» Site Navigation
 > FAQ
  > 10.0.0.2


All times are GMT -7. The time now is 11:00 AM.


Copyright 2001 - 2014, Tech Support Forum

Windows 7 - Windows XP - Windows Vista - Trojan Removal - Spyware Removal - Virus Removal - Networking - Security - Top Web Hosts