| | |
help me on this tutorial
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2009
Posts: 66
Reputation:
Solved Threads: 0
heey guys..
i just learned the arrays.. am not really good at them..
can some one simplify it for me..
i gat this question.. i tried to solve it.. but didn't get the desired output
how ever it says 1 succeeded !
here's the Q:
1. Declare one array for storing the square roots of the integers from 0 through 10.
2. Declare one array for storing the cubes of the same integers.
3. Write a program that reads 10 integers and prints them in reverse order .
this is my work.. i'm pretty sure it's wrong..
i just learned the arrays.. am not really good at them..
can some one simplify it for me..
i gat this question.. i tried to solve it.. but didn't get the desired output

how ever it says 1 succeeded !
here's the Q:
1. Declare one array for storing the square roots of the integers from 0 through 10.
2. Declare one array for storing the cubes of the same integers.
3. Write a program that reads 10 integers and prints them in reverse order .
this is my work.. i'm pretty sure it's wrong..
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main () { int SQUARE_ROOTS [10]; cout<<"Enter 10 numbers:"<<endl; for(int i=1;i>=10;i++) cin>>SQUARE_ROOTS [i]; for(int i=1;i>=10;i--) cout<<"The numbers in reverse order are:"<<endl <<SQUARE_ROOTS [i]; return 0; }
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
You shouldn't read in a square root or a cube. You CALCULATE the square root or the cube. Thus this is incorrect:
Don't read in data into the SQUARE_ROOTS array. You shouldn't be reading numbers in from the user in this part of the program anyway.
The numbers range from 0 to 10. There is no need to ask for user input.
You ask for user input in the third part.
but that has nothing to do with cubing or taking a square root, so create a different array and call it something different (i.e.
C++ Syntax (Toggle Plain Text)
cout<<"Enter 10 numbers:"<<endl; for(int i=1;i>=10;i++) cin>>SQUARE_ROOTS [i];
Don't read in data into the SQUARE_ROOTS array. You shouldn't be reading numbers in from the user in this part of the program anyway.
•
•
•
•
1. Declare one array for storing the square roots of the integers from 0 through 10.
2. Declare one array for storing the cubes of the same integers.
You ask for user input in the third part.
•
•
•
•
3. Write a program that reads 10 integers and prints them in reverse order .
userInput ). •
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
There's not much anyone can do with this post. The obvious question is "What part of my post don't you understand?" We aren't mind readers and posting on a forum requires some effort on your part. You need to ask a specific question.
•
•
Join Date: May 2009
Posts: 27
Reputation:
Solved Threads: 2
Hi
your question is you just store square rott and cube of first 10 integers.And in your code you get user user input which is incorrect.
First of all you just run a for loop of maximum 10 values in which you do your work e.g square root anf cube anf ten store them in arrays.
If you cannot understand or feel difficulty in coding tell me i will help you and give you a code.
your question is you just store square rott and cube of first 10 integers.And in your code you get user user input which is incorrect.
First of all you just run a for loop of maximum 10 values in which you do your work e.g square root anf cube anf ten store them in arrays.
If you cannot understand or feel difficulty in coding tell me i will help you and give you a code.
besides arrays you should also brush up on for loops...
neither of those will even be entered into (seeing as 1 is NOT greater than or equal to 10). For the first loop you'd need to switch it to this for your code to at least make sense:
and your second loop
notice I switched it from going from 1-10 and 10-1 to 0-9 and 9-0 because arrays use a 0 index for the first element. Look over this loop and see if you can get the idea of how it's getting filled
hope that's helpful
~J
neither of those will even be entered into (seeing as 1 is NOT greater than or equal to 10). For the first loop you'd need to switch it to this for your code to at least make sense:
C++ Syntax (Toggle Plain Text)
for(int i = 0; i < 10; i++)
and your second loop
C++ Syntax (Toggle Plain Text)
for(int i = 9; i >= 0; i--);
notice I switched it from going from 1-10 and 10-1 to 0-9 and 9-0 because arrays use a 0 index for the first element. Look over this loop and see if you can get the idea of how it's getting filled
C++ Syntax (Toggle Plain Text)
int values[10]; for(int x = 0; x < 10; x++) { values[x] = x+1; //values[0] = 1, ... values[9] = 10 std::cout << "values[" << x << "] = " << values[x] << std::endl; }
hope that's helpful
~J
Last edited by jesseb07; May 29th, 2009 at 5:20 pm. Reason: added cout
Ps. 121
Makes it easier on everyone: http://www.daniweb.com/forums/thread78223.html
AJAX, PHP, C#, C++, JAVA
Makes it easier on everyone: http://www.daniweb.com/forums/thread78223.html
AJAX, PHP, C#, C++, JAVA
•
•
Join Date: May 2009
Posts: 27
Reputation:
Solved Threads: 2
•
•
•
•
yeah i'm having some difficulties to understand anything written.. i need some examples to get a certain idea.. if u don't mind give me an example for a similar question..
thnks
cpp Syntax (Toggle Plain Text)
//This code store cube of an integer in an array // declarations int array[]; int store; for ( int c=1;c<=10;c++ ) { // primary storage store = c*c*c; // store cube of the integer in an array array [c] = store; } // for 'c' is the value of an integer which increases as 1,2,3,.......,10. // Display in reverse order for (int c=1;c<=10;c++ ) { // store value in an array array[c] = c; }//for for (int c=10;c--) { // display array in reverse order cout << array[c]; }/for
Last edited by Tekmaven; May 30th, 2009 at 9:06 pm. Reason: Code Tags
![]() |
Similar Threads
- C++ Tutorial (C++)
- Windows Api Tutorial (C++)
Other Threads in the C++ Forum
- Previous Thread: Re: SQL ado
- Next Thread: multiply using << several times
Views: 579 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






