944,000 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2546
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 10th, 2009
0
Re: to calculate square and cube form given input using arrays..
This should work now. You gotta learn arrays, passing arrays to functions, returning arrays, etc. profoundly in order to master arrays.

C++ Syntax (Toggle Plain Text)
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5.  
  6.  
  7. using namespace std;
  8. const int size = 10;
  9. void square_store (int [], int []);
  10. void read_numbers (int []);
  11. void cube_store (int [], int []);
  12.  
  13. int main(int argc, char *argv[]){
  14. const int size = 10;
  15. static int values[size], square_array [size], cube_array[size];
  16. int i [size];
  17.  
  18. read_numbers (values);
  19. square_store (square_array, values);
  20. cube_store (cube_array, values);
  21.  
  22. cout << "\n\n";
  23. system("PAUSE");
  24. return EXIT_SUCCESS;
  25. }//main() ends
  26.  
  27. void read_numbers (int values[]){
  28. int index;
  29. cout << "Enter 10 numbers:\n";
  30. for (index = 0; index < size; index++)
  31. cin >> values [index];
  32. }//read_numbers() ends
  33.  
  34. void square_store (int square_array[], int values[]){
  35.  
  36. int index;
  37. cout << "\nThe square of your input numbers are:\n";
  38. for (index = 0; index < size; index++){
  39. square_array [index] = values [index] * values [index];
  40. cout << "\n\n";
  41. cout << "Square is ---> " << square_array [index];
  42. }
  43. }//square_store() ends
  44.  
  45. void cube_store ( int cube_array[], int values[]){
  46. int i;
  47. cout << "\n\nThe cubes of the numbers are:\n";
  48. for (i = 0; i < size; i++){
  49. cube_array [i] = values [i] * values [i] * values [i];
  50. cout << "\n\n";
  51. cout << "Cube is ---> " << cube_array[i];
  52. }
  53. }//cube_store() ends

As pointed by jonsca, there are many tuts/ebboks on the 'firehose of information'(the Internet).

Cheers
Reputation Points: 11
Solved Threads: 7
Junior Poster
abhi_elementx is offline Offline
118 posts
since Dec 2007

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: const char array problem
Next Thread in C++ Forum Timeline: Internet Provider Switch Program Help





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


Follow us on Twitter


© 2011 DaniWeb® LLC