Homework assignment
Question posted by: PAK11
(Newbie)
on
March 27th, 2008 08:02 PM
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!
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
|
|
March 27th, 2008 08:17 PM
# 2
|
Re: Homework assignment
Quote:
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?
|
|
March 27th, 2008 08:56 PM
# 3
|
Re: Homework assignment
Quote:
Originally Posted by Sick0Fant
Quincy? Do you go to NIU?
|
No I don't. I go to NC State...you know anything about this?
|
|
March 27th, 2008 09:00 PM
# 4
|
Re: Homework assignment
Quote:
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<iostream.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)<<endl;
num1=num1+1;
}while(num1<num2);
return 0;
}
|
|
March 27th, 2008 09:00 PM
# 5
|
Re: Homework assignment
Quote:
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.
|
|
March 27th, 2008 09:03 PM
# 6
|
Re: Homework assignment
Quote:
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?
|
|
March 27th, 2008 09:04 PM
# 7
|
Re: Homework assignment
Quote:
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<iostream.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)<<endl;
num1=num1+1;
}while(num1<num2);
return 0;
}
|
You might want to put some spaces inbetween numbers... or format them, which is probably what your instructor wants
|
|
March 27th, 2008 09:11 PM
# 8
|
Re: Homework assignment
Quote:
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.
|
|
March 27th, 2008 09:17 PM
# 9
|
Re: Homework assignment
Quote:
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.
|
|
March 27th, 2008 09:40 PM
# 10
|
Re: Homework assignment
Quote:
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<iostream.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\tSquare\tCube"<<endl;
for(int i=2;i<num2;i++-1)
{
cout<<num1<<pow(num1,2)<<pow(num1,3)<<endl;
num1=num1+1;
}
return 0;
}
|
|
March 27th, 2008 09:56 PM
# 11
|
Re: Homework assignment
Quote:
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<iostream.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\tSquare\tCube"<<endl;
for(int i=2;i<num2;i++-1)
{
cout<<num1<<pow(num1,2)<<pow(num1,3)<<endl;
num1=num1+1;
}
return 0;
}
|
Nevermind I figured it out, thanks for the help
Not the answer you were looking for? Post your question . . .
169,970 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Top C / C++ Forum Contributors
|