help me on this tutorial

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 63
Reputation: fadia is an unknown quantity at this point 
Solved Threads: 0
fadia fadia is offline Offline
Junior Poster in Training

help me on this tutorial

 
0
  #1
May 29th, 2009
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..


  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. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,820
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: help me on this tutorial

 
0
  #2
May 29th, 2009
You shouldn't read in a square root or a cube. You CALCULATE the square root or the cube. Thus this is incorrect:

  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.

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.

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 ).
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 63
Reputation: fadia is an unknown quantity at this point 
Solved Threads: 0
fadia fadia is offline Offline
Junior Poster in Training

Re: help me on this tutorial

 
0
  #3
May 29th, 2009
i didn't really understood that..

thanks though
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,820
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: help me on this tutorial

 
0
  #4
May 29th, 2009
Originally Posted by fadia View Post
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.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 27
Reputation: mirfan00 has a little shameless behaviour in the past 
Solved Threads: 2
mirfan00 mirfan00 is offline Offline
Light Poster

Re: help me on this tutorial

 
0
  #5
May 29th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 63
Reputation: fadia is an unknown quantity at this point 
Solved Threads: 0
fadia fadia is offline Offline
Junior Poster in Training

Re: help me on this tutorial

 
0
  #6
May 29th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 111
Reputation: jesseb07 is on a distinguished road 
Solved Threads: 15
jesseb07's Avatar
jesseb07 jesseb07 is offline Offline
Junior Poster

Re: help me on this tutorial

 
0
  #7
May 29th, 2009
Originally Posted by fadia View Post

  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:
  1. for(int i = 0; i < 10; i++)

and your second loop
  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

  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
Ps. 121

Makes it easier on everyone: http://www.daniweb.com/forums/thread78223.html

AJAX, PHP, C#, C++, JAVA
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 27
Reputation: mirfan00 has a little shameless behaviour in the past 
Solved Threads: 2
mirfan00 mirfan00 is offline Offline
Light Poster

Re: help me on this tutorial

 
0
  #8
May 30th, 2009
Originally Posted by fadia View Post
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.
  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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,820
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: help me on this tutorial

 
0
  #9
May 30th, 2009
Originally Posted by mirfan00 View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 32
Reputation: Ahmed_I is an unknown quantity at this point 
Solved Threads: 1
Ahmed_I Ahmed_I is offline Offline
Light Poster

Re: help me on this tutorial

 
0
  #10
May 30th, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC