943,916 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 866
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
May 29th, 2009
0

help me on this tutorial

Expand Post »
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..


C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6.  
  7. int SQUARE_ROOTS [10];
  8.  
  9.  
  10. cout<<"Enter 10 numbers:"<<endl;
  11. for(int i=1;i>=10;i++)
  12. cin>>SQUARE_ROOTS [i];
  13.  
  14.  
  15.  
  16. for(int i=1;i>=10;i--)
  17.  
  18. cout<<"The numbers in reverse order are:"<<endl
  19. <<SQUARE_ROOTS [i];
  20.  
  21.  
  22.  
  23. return 0;
  24. }
Similar Threads
Reputation Points: 7
Solved Threads: 0
Junior Poster in Training
fadia is offline Offline
89 posts
since Apr 2009
May 29th, 2009
0

Re: help me on this tutorial

You shouldn't read in a square root or a cube. You CALCULATE the square root or the cube. Thus this is incorrect:

C++ Syntax (Toggle Plain Text)
  1. cout<<"Enter 10 numbers:"<<endl;
  2. for(int i=1;i>=10;i++)
  3. 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.

Quote ...
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.
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.

Quote ...
3. Write a program that reads 10 integers and prints them in reverse order .
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. userInput ).
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
May 29th, 2009
0

Re: help me on this tutorial

i didn't really understood that..

thanks though
Reputation Points: 7
Solved Threads: 0
Junior Poster in Training
fadia is offline Offline
89 posts
since Apr 2009
May 29th, 2009
0

Re: help me on this tutorial

Click to Expand / Collapse  Quote originally posted by fadia ...
i didn't really understood that..

thanks though
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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
May 29th, 2009
0

Re: help me on this tutorial

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.
Reputation Points: -9
Solved Threads: 2
Light Poster
mirfan00 is offline Offline
29 posts
since May 2009
May 29th, 2009
0

Re: help me on this tutorial

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
Reputation Points: 7
Solved Threads: 0
Junior Poster in Training
fadia is offline Offline
89 posts
since Apr 2009
May 29th, 2009
0

Re: help me on this tutorial

Click to Expand / Collapse  Quote originally posted by fadia ...

C++ Syntax (Toggle Plain Text)
  1.  
  2. for(int i=1;i>=10;i++)
  3.  
  4. for(int i=1;i>=10;i--)
  5.  
  6. }
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:
C++ Syntax (Toggle Plain Text)
  1. for(int i = 0; i < 10; i++)

and your second loop
C++ Syntax (Toggle Plain Text)
  1. 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)
  1. int values[10];
  2.  
  3. for(int x = 0; x < 10; x++)
  4. {
  5. values[x] = x+1; //values[0] = 1, ... values[9] = 10
  6.  
  7. std::cout << "values[" << x << "] = " << values[x] << std::endl;
  8. }

hope that's helpful

~J
Last edited by jesseb07; May 29th, 2009 at 5:20 pm. Reason: added cout
Reputation Points: 76
Solved Threads: 15
Junior Poster
jesseb07 is offline Offline
111 posts
since Dec 2006
May 30th, 2009
0

Re: help me on this tutorial

Click to Expand / Collapse  Quote originally posted by fadia ...
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
Dear I'll try my level best to solve your problem.
cpp Syntax (Toggle Plain Text)
  1. //This code store cube of an integer in an array
  2. // declarations
  3. int array[];
  4. int store;
  5. for ( int c=1;c<=10;c++ ) {
  6. // primary storage
  7. store = c*c*c;
  8. // store cube of the integer in an array
  9. array [c] = store;
  10. } // for
  11. 'c' is the value of an integer which increases as 1,2,3,.......,10.
  12. // Display in reverse order
  13. for (int c=1;c<=10;c++ ) {
  14. // store value in an array
  15. array[c] = c;
  16. }//for
  17. for (int c=10;c--) {
  18. // display array in reverse order
  19. cout << array[c];
  20.  
  21. }/for
I hope you enjoy it. Any problem tell me.
Last edited by Tekmaven; May 30th, 2009 at 9:06 pm. Reason: Code Tags
Reputation Points: -9
Solved Threads: 2
Light Poster
mirfan00 is offline Offline
29 posts
since May 2009
May 30th, 2009
0

Re: help me on this tutorial

Click to Expand / Collapse  Quote originally posted by mirfan00 ...
Any problem tell me.
Three problems. One, use code tags. Two, don't give away all the code. Give hints and advice. Three, if you decide to give away all the code, make sure it's code that compiles.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
May 30th, 2009
0

Re: help me on this tutorial

Don't forget to declare the array as float not int cuz it gonna receive the square roots of the integers which can be float numbers.
Reputation Points: 14
Solved Threads: 1
Light Poster
Ahmed_I is offline Offline
32 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Re: SQL ado
Next Thread in C++ Forum Timeline: multiply using << several times





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC