the power function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #31
    Try declaring sum right before your for loop.

    Comment

    • logicode
      New Member
      • Apr 2007
      • 22

      #32
      Originally posted by sicarie
      Try declaring sum right before your for loop.
      I get one error when I try to run it says parse error and points to
      for (int i = 0; i < exp; i++; )

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #33
        Originally posted by logicode
        I get one error when I try to run it says parse error and points to
        for (int i = 0; i < exp; i++;);
        Just a slight syntax error - try removing the semi-colon from the right side of the for loop.

        Comment

        • logicode
          New Member
          • Apr 2007
          • 22

          #34
          Originally posted by sicarie
          Just a slight syntax error - try removing the semi-colon from the right side of the for loop.
          ahh ok I dont know why but that works so here is the thing
          I input 5
          then input 2
          it says that the answer is 5
          cout<<sum

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #35
            Originally posted by logicode
            ahh ok I dont know why but that works so here is the thing
            I input 5
            then input 2
            it says that the answer is 5
            cout<<sum
            And your main follows pseudocode of:

            declare vars
            get input
            call function
            save function return value
            print function return value

            ?

            Comment

            • logicode
              New Member
              • Apr 2007
              • 22

              #36
              can I send in my code so you can see it

              Comment

              • logicode
                New Member
                • Apr 2007
                • 22

                #37
                Code:
                  for (int i = 0; i < exp; i++);
                  {
                    sum= base*sum;
                     return sum;
                   }
                Last edited by sicarie; Apr 5 '07, 04:19 AM. Reason: Please use [code] and [/code] tags around your code.

                Comment

                • sicarie
                  Recognized Expert Specialist
                  • Nov 2006
                  • 4677

                  #38
                  Your return statement - you have it inside your for loop. This means you return on the first execution of the loop. You want to return when the loop is completed.

                  Comment

                  • logicode
                    New Member
                    • Apr 2007
                    • 22

                    #39
                    Code:
                      for (int i = 0; i < exp; i++);
                    {
                        sum= base*sum;
                    }
                          return sum;
                    
                    }
                    ok I should have seen that but in this one All I get in return is the origional value
                    Last edited by sicarie; Apr 5 '07, 01:38 PM. Reason: Full code removed per FAQ, and please use [code] and [/code] tags.

                    Comment

                    • sicarie
                      Recognized Expert Specialist
                      • Nov 2006
                      • 4677

                      #40
                      Code:
                        for (int i = 0; i < exp; i++);
                      You still have a ';' after your for loop, remove that. For statements are a little weird in that they are not terminated by a semicolon, but the stuff inside them still is.
                      Code:
                      doStuff();
                      for (part1; part1; part3) {             // no ';' here
                          initialize.someVariable();        // ended with a semicolon
                      }                                              // no ';' here either
                      doStuff(with.someVariable());     // ended with a semicolon

                      Comment

                      • Michael Safyan
                        New Member
                        • Oct 2007
                        • 1

                        #41
                        Before I begin...
                        To answer the question...

                        Code:
                        Code removed - please read posting guidelines.

                        Comment

                        Working...