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

New Free Tools on Dev Shed!

#1
August 18th, 2013, 01:46 PM
 fxlightning06
Registered User

Join Date: Aug 2013
Posts: 7
Time spent in forums: 1 h 22 m 53 sec
Reputation Power: 0
Help A New Programmer

Hi everyone, After trying to figure this out on my own I am going to ask you guys for help because these forums have been more of a help than anyone who has tried to assist me.

This is the logic I am attempting to code.

start
var1 = 10
var2 = 20
wksum = 0
rslt = 0
do while var2 < 30
wksum = var1 + var2
if wksum > 30
var1 = var1 - 2
var2 = var2 + 1
else
var1 = var1 - 1
var2 = var2 + 3
end if
end while loop
rslt = var1 + var2
display rslt
end

What I have at this point is

var msg;
var Var1 = 10;
var Var2 = 20;
var Weeksum = 0;
var Result = 0;
while(Var2 < 30)
{
Weeksum =(Var1m + Var2);
}
else if(Weeksum > 30)
{
Var1 = (Var1 - 2);
Var2 = (Var2 + 1);
}
else
{
Var1 = (Var1 - 1);
Var2 = (Var2 + 3);
}

}
Result = (Var1 + Var2);
Prompt.Write(Result)

It is just failing for me. What is throwing me off is the end loop. I am not sure how to articulate it in a program. Any help would be appreciated. My syntax may be a bit different then most but that is because I am learning in the Newbie way so to speak.

#2
August 18th, 2013, 09:09 PM
 mbrown3391
Registered User

Join Date: Aug 2013
Posts: 13
Time spent in forums: 2 h 56 m 35 sec
Reputation Power: 0
First of all, you should indent your code to make it more legible.
Code:
```var msg;
var Var1 = 10;
var Var2 = 20;
var Weeksum = 0;
var Result = 0;

while(Var2 < 30)
{
//Now it becomes clear that you are missing an opening if statement...
Weeksum = (Var1 + Var2);
}
else if(Weeksum > 30)
{
Var1 = (Var1 - 2);
Var2 = (Var2 + 1);
}
else
{
Var1 = (Var1 - 1);
Var2 = (Var2 + 3);
}
}

Result = (Var1 + Var2);
Prompt.Write(Result)```

I have no idea what you intend this program to do, but it looks like you might mean this:
Code:
```var msg;
var Var1 = 10;
var Var2 = 20;
var Weeksum = 0;
var Result = 0;

do
{
Weeksum = (Var1 + Var2);

if(Weeksum > 30)
{
Var1 = (Var1 - 2);
Var2 = (Var2 + 1);
}
else
{
Var1 = (Var1 - 1);
Var2 = (Var2 + 3);
}
} while(Var2 < 30);

Result = (Var1 + Var2);
Prompt.Write(Result);```

#3
August 18th, 2013, 09:54 PM
 fxlightning06
Registered User

Join Date: Aug 2013
Posts: 7
Time spent in forums: 1 h 22 m 53 sec
Reputation Power: 0
Quote:
 Originally Posted by mbrown3391 First of all, you should indent your code to make it more legible. Code: ```var msg; var Var1 = 10; var Var2 = 20; var Weeksum = 0; var Result = 0; while(Var2 < 30) { //Now it becomes clear that you are missing an opening if statement... Weeksum = (Var1 + Var2); } else if(Weeksum > 30) { Var1 = (Var1 - 2); Var2 = (Var2 + 1); } else { Var1 = (Var1 - 1); Var2 = (Var2 + 3); } } Result = (Var1 + Var2); Prompt.Write(Result)``` I have no idea what you intend this program to do, but it looks like you might mean this: Code: ```var msg; var Var1 = 10; var Var2 = 20; var Weeksum = 0; var Result = 0; do { Weeksum = (Var1 + Var2); if(Weeksum > 30) { Var1 = (Var1 - 2); Var2 = (Var2 + 1); } else { Var1 = (Var1 - 1); Var2 = (Var2 + 3); } } while(Var2 < 30); Result = (Var1 + Var2); Prompt.Write(Result);```

Thanks a lot. I am struggling to read logic and then articulate it to others for help. But thanks for taking the time to help.

 Viewing: Dev Shed Forums > Web Design > JavaScript Development > Help A New Programmer