#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    40
    Rep Power
    1

    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. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    13
    Rep 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);
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    40
    Rep Power
    1
    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.

IMN logo majestic logo threadwatch logo seochat tools logo