# Visual logic While Loop Question



## Rick_In_Tampa

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.


----------



## Special2God

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.


----------



## Rick_In_Tampa

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




Special2God said:


> 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

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]

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 :grin:


----------



## AlbertMC2

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.


----------



## jhmkmacoolcs

Rick_In_Tampa said:


> 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}


----------



## Special2God

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.


----------

