Homework assignment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PAK11
    New Member
    • Mar 2008
    • 11

    Homework assignment

    I'm using Quincy for a computer programming class and its an internet class. I'm having the hardest time doing this project:

    *Create a math table which displays a series of numbers, the squares of the numbers and the
    cubes of the numbers. The program should prompt the user to enter 2 values which will be the
    beginning number for the table and the ending number for the table. After that a loop should be
    used to display each number in the series, the square and the cube of that number as shown for
    4 to 7 below. The loop should begin at the first number entered by the user and end with the last
    number entered by the user.*

    Can someone please help me out or atleast point me in the right direction? I have no clue how to do this!
  • Sick0Fant
    New Member
    • Feb 2008
    • 121

    #2
    Originally posted by PAK11
    I'm using Quincy for a computer programming class and its an internet class. I'm having the hardest time doing this project:

    *Create a math table which displays a series of numbers, the squares of the numbers and the
    cubes of the numbers. The program should prompt the user to enter 2 values which will be the
    beginning number for the table and the ending number for the table. After that a loop should be
    used to display each number in the series, the square and the cube of that number as shown for
    4 to 7 below. The loop should begin at the first number entered by the user and end with the last
    number entered by the user.*

    Can someone please help me out or atleast point me in the right direction? I have no clue how to do this!
    Quincy? Do you go to NIU?

    Comment

    • PAK11
      New Member
      • Mar 2008
      • 11

      #3
      Originally posted by Sick0Fant
      Quincy? Do you go to NIU?
      No I don't. I go to NC State...you know anything about this?

      Comment

      • PAK11
        New Member
        • Mar 2008
        • 11

        #4
        Originally posted by PAK11
        No I don't. I go to NC State...you know anything about this?
        Ok sorry for not showing any work before....this is what I have so far and it will compile and build It just doesn't look right:

        #include<iostre am.h>
        #include<cmath>

        int main()
        {
        int num1=0;
        int num2=0;


        cout<<"Please enter the first number"<<endl;
        cin>>num1;
        cout<<"Please enter the second number"<<endl;
        cin>>num2;

        cout<<"Math Table"<<endl;
        cout<<"Number Square Cube"<<endl;

        do
        {
        cout<<num1<< pow(num1,2)<< pow(num1,3)<<en dl;
        num1=num1+1;
        }while(num1<num 2);


        return 0;
        }

        Comment

        • Sick0Fant
          New Member
          • Feb 2008
          • 121

          #5
          Originally posted by PAK11
          No I don't. I go to NC State...you know anything about this?
          Yes. If you know how to use a for loop and you know how to square a number, the code would be about a quarter of a page.

          Comment

          • PAK11
            New Member
            • Mar 2008
            • 11

            #6
            Originally posted by Sick0Fant
            Yes. If you know how to use a for loop and you know how to square a number, the code would be about a quarter of a page.
            Can you tell me what is wrong with my program so far?

            Comment

            • Sick0Fant
              New Member
              • Feb 2008
              • 121

              #7
              Originally posted by PAK11
              Ok sorry for not showing any work before....this is what I have so far and it will compile and build It just doesn't look right:

              #include<iostre am.h>
              #include<cmath>

              int main()
              {
              int num1=0;
              int num2=0;


              cout<<"Please enter the first number"<<endl;
              cin>>num1;
              cout<<"Please enter the second number"<<endl;
              cin>>num2;

              cout<<"Math Table"<<endl;
              cout<<"Number Square Cube"<<endl;

              do
              {
              cout<<num1<< pow(num1,2)<< pow(num1,3)<<en dl;
              num1=num1+1;
              }while(num1<num 2);


              return 0;
              }
              You might want to put some spaces inbetween numbers... or format them, which is probably what your instructor wants

              Comment

              • PAK11
                New Member
                • Mar 2008
                • 11

                #8
                Originally posted by Sick0Fant
                You might want to put some spaces inbetween numbers... or format them, which is probably what your instructor wants
                Yes my instructor wants a table format. I was going to use "\t" to space my numbers. My real problem is after I have asked for the user input, say 3 and 5, I am not sure how to include, within my loop, the process to get 3,4 and 5 all squared and cubed on the table.

                Comment

                • Sick0Fant
                  New Member
                  • Feb 2008
                  • 121

                  #9
                  Originally posted by PAK11
                  Yes my instructor wants a table format. I was going to use "\t" to space my numbers. My real problem is after I have asked for the user input, say 3 and 5, I am not sure how to include, within my loop, the process to get 3,4 and 5 all squared and cubed on the table.
                  Well, that's why you'll need to use iomanip. You can find how much space your largest number squared will take (since the user is supplying them at runtime.). If you just use tabs, your table will start to look askew.

                  Comment

                  • PAK11
                    New Member
                    • Mar 2008
                    • 11

                    #10
                    Originally posted by Sick0Fant
                    Well, that's why you'll need to use iomanip. You can find how much space your largest number squared will take (since the user is supplying them at runtime.). If you just use tabs, your table will start to look askew.
                    Sorry I don't know what you mean by tabs....Can you show me what i need to put? This is what I have and the numbers within my for statement are not spacing.

                    #include<iostre am.h>
                    #include<cmath>

                    int main()
                    {
                    int num1=0;
                    int num2=0;


                    cout<<"Please enter the first number"<<endl;
                    cin>>num1;
                    cout<<"Please enter the second number"<<endl;
                    cin>>num2;

                    cout<<"Math Table"<<endl;
                    cout<<" "<<endl;
                    cout<<"Number\t Square\tCube"<< endl;

                    for(int i=2;i<num2;i++-1)
                    {
                    cout<<num1<<pow (num1,2)<<pow(n um1,3)<<endl;
                    num1=num1+1;
                    }

                    return 0;
                    }

                    Comment

                    • PAK11
                      New Member
                      • Mar 2008
                      • 11

                      #11
                      Originally posted by PAK11
                      Sorry I don't know what you mean by tabs....Can you show me what i need to put? This is what I have and the numbers within my for statement are not spacing.

                      #include<iostre am.h>
                      #include<cmath>

                      int main()
                      {
                      int num1=0;
                      int num2=0;


                      cout<<"Please enter the first number"<<endl;
                      cin>>num1;
                      cout<<"Please enter the second number"<<endl;
                      cin>>num2;

                      cout<<"Math Table"<<endl;
                      cout<<" "<<endl;
                      cout<<"Number\t Square\tCube"<< endl;

                      for(int i=2;i<num2;i++-1)
                      {
                      cout<<num1<<pow (num1,2)<<pow(n um1,3)<<endl;
                      num1=num1+1;
                      }

                      return 0;
                      }
                      Nevermind I figured it out, thanks for the help

                      Comment

                      Working...