Been working on a program that is suppose to Loop and display 13 times. Here is my code
{
var count;
var user_Input;
var output_msg;
var cel;
count = 0;
do
{
user_Input = get_integer("Temperature conversion","");
count = count + 1;
cel = user_Input * 9/5 +32;
user_Input = user_Input +10;
output_msg =(string(count) + "Celsius" + string(user_Input) + " = Farenheit " + string(cel));
show_message(output_msg);
}
until (count == 13)
}
What It Does is it Displays the loop each time I hit enter instead of showing all 13 at once also if i enter 10 for example each time it loops its suppose to add 10 from the last loop.
eg. 1. Celsius 10 = Farenheit (answer here)
..... 2. Celsius 20 = Farenheit (answer Here)
......13. Celsuis 130 = Farenheit ""
if some one could walk me through and help me that would be great
What you'll have to do is :
show_message
outside the loop, well, after the Do
loop to be precise. Then, it will be displayed only at the end of the loop, while the get_integer
dialog box will of course wait for the user to enter a value.get_integer
aswell outside the loop, right before it. User will just have to input value once. If you put it inside the loop, you'll be asked to enter a value 13th times...output_msg
to itself, with the line feed "#"
at the end.{
var count = 0;
var user_Input;
var output_msg = "";
var cel;
count = 0;
user_Input = get_integer("Temperature conversion","");
do
{
count = count + 1;
cel = user_Input * 9 / 5 + 32;
user_Input = user_Input + 10;
output_msg = (output_msg + string(count) + ". Celsius" + string(user_Input) + " = Farenheit " + string(cel) + "#");
}
until (count == 13)
show_message(output_msg);
}
For clarity, I've initialized some variables initial values.
Your issue is not a code issue, it's a logic issue (except for the line feed) Everything inside a loop, (Do, While) will be executed on every iteration. If you don't want something to be executed, you must either move it outside the loop (before/after), or use a condition check.