on my assignment I need to ask a user for two numbers
output all the odd # between the two #
output the sum of the even #
*output the # and squares between 1-10*
*output the sum of the square of the odd numbers between #1 and #2*
now I can get the first part but when it comes to the squares between 1-10 my code does not work, and I am not sure why
cout << "1 squared is: " << pow(1, 2) << endl;
cout << "2 squared is: " << pow(2, 2) << endl;
cout << "3 squared is: " << pow(3, 2) << endl;
cout << "4 squared is: " << pow(4, 2) << endl;
cout << "5 squared is: " << pow(5, 2) << endl;
cout << "6 squared is: " << pow(6, 2) << endl;
cout << "7 squared is: " << pow(7, 2) << endl;
cout << "8 squared is: " << pow(8, 2) << endl;
cout << "9 squared is: " << pow(9, 2) << endl;
cout << "10 squared is: " << pow(10, 2) << endl;
Hunderpanzer said
"Well the line of code listed above would work if the user input 1 as a number, but remember that the user can start the firstNumb at 50 and the secondNumb at 70. In your code, it would then print the squares of 1- 10 which isn't the right result."
but all I need it to do is square 1-10, but I keep getting an error.
do I need to put in more variables for the squares?
3 6613
on my assignment I need to ask a user for two numbers
output all the odd # between the two #
output the sum of the even #
*output the # and squares between 1-10*
*output the sum of the square of the odd numbers between #1 and #2*
now I can get the first part but when it comes to the squares between 1-10 my code does not work, and I am not sure why
cout << "1 squared is: " << pow(1, 2) << endl;
cout << "2 squared is: " << pow(2, 2) << endl;
cout << "3 squared is: " << pow(3, 2) << endl;
cout << "4 squared is: " << pow(4, 2) << endl;
cout << "5 squared is: " << pow(5, 2) << endl;
cout << "6 squared is: " << pow(6, 2) << endl;
cout << "7 squared is: " << pow(7, 2) << endl;
cout << "8 squared is: " << pow(8, 2) << endl;
cout << "9 squared is: " << pow(9, 2) << endl;
cout << "10 squared is: " << pow(10, 2) << endl;
Hunderpanzer said
"Well the line of code listed above would work if the user input 1 as a number, but remember that the user can start the firstNumb at 50 and the secondNumb at 70. In your code, it would then print the squares of 1- 10 which isn't the right result."
but all I need it to do is square 1-10, but I keep getting an error.
do I need to put in more variables for the squares?
I don't under stand why you need all those couts when you can use a simple for loop: -
for (int x = 1; x <= 10; x++)
-
{
-
cout << x << " squared is: " << x*x << endl;
-
}
-
I don't under stand why you need all those couts when you can use a simple for loop:
Code: ( cpp )
for (int x = 1; x <= 10; x++)
{
cout << x << " squared is: " << x*x << endl;
}
To be honest it is the only way I could think to do it
but I see how you are saying it just loop it so that it goes up to 10, dang that is a lot easier way to do it
how about if I needed to raise it to the third power just use
cout << x << " squared is: " << x*x*x << endl;
Thank you, I am just learning how to write programs in C++ so I don't have my head around all the great short cuts/ good ways to do things.
Though the other solution is more elegant, I wanted to post in case there are any searches later with this issue. With the pow() function, you have to be sure to include the math.h library. (With that, your original code will compile and run)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: cplusplus |
last post by:
Hello, I have newbie question.
I'm stuck on this current assignment.
Write a program that prompts the user for two integer values,
passes the values to a function where they are multiplied...
|
by: Stavros Christoforou |
last post by:
Hello everyone,
I was wondering if someone could help me with an issue I have in C++. I
want to select random points within the volume of a sphere. I know how
to get random numbers using srand()...
|
by: brian.digipimp |
last post by:
Write a program that prompts the user to input a positive integer. It
should then output a message indicating whether the number is a prime
number. (Note: An even number is prime if it is 2. An odd...
|
by: Mike Meyer |
last post by:
In the discussion of equality, the issue that decimal('3.0') == 3.0 is
False came up as a reason for changing the behavior of ==. The problem
with this is that the proposed change doesn't really...
|
by: johnmsimon |
last post by:
i need to develop a code that finds a prime right number between 2 and
100000. and print one line of text that indicates if the int. is right
prime. i am in beginning programing so complex is...
|
by: newstips6706 |
last post by:
1, 2, 3, 5, 7... PRIME Numbers
________________________________
Definitions
What is a PRIME Number ?
|
by: shihaoran |
last post by:
I really need help with one my program; it is about arraylist; I do not get it. Can someone please help me with it?
Here's the instruction:
1. Your instructor will provide you with a text...
|
by: cmeekeen |
last post by:
How do I square the numbers in the even rows? I have generated 100 integer random numbers in the range of 1 to 100 in array x(10,10).
Private Sub Form_Activate()
Const row As Integer = 10
Const...
|
by: mandanarchi |
last post by:
I've hunted for info about this and come up with loads.
Jet 4.0 error - fixed in latest service pack. We all have latest service pack.
Copy faulty table, delete old, remove fault field etc
This...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |