Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Array Problem

Array Problem

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structureshelptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aaadetos
    wrote on last edited by
    #1

    Hi, im trying to use the specific value of an array in a computation in another function; but don't know how to set it up. In test(), i want to use the 6th value of C[] in the computation. How do i set this up please? #include "stdafx.h" #include const int size = 10; double A[size] = {0},B[size] = {0}, C[size],c,d; double PI = 3.141592653589793238462643383279502884197; void rah(double C[]) { for (int i=0;i

    N D 2 Replies Last reply
    0
    • A aaadetos

      Hi, im trying to use the specific value of an array in a computation in another function; but don't know how to set it up. In test(), i want to use the 6th value of C[] in the computation. How do i set this up please? #include "stdafx.h" #include const int size = 10; double A[size] = {0},B[size] = {0}, C[size],c,d; double PI = 3.141592653589793238462643383279502884197; void rah(double C[]) { for (int i=0;i

      N Offline
      N Offline
      narendra_ b
      wrote on last edited by
      #2

      i am not clear abt ur requirement. try this #include #include const int size = 10; double A[size] = {0},B[size] = {0}, C[size],c,d; double PI = 3.141592653589793238462643383279502884197; double rah(double *C) { int i = C-::C ; A[i] = sqrt(10*i); B[i] = 2*PI*i; ::C[i] = A[i]*B[i]; return ::C[i] ; } double test()//how do i write this correctly? { d = PI * rah(&C[5]); return d ; } int main(int argc, char* argv[]) { printf("Hello World!\n %f", test()); return 0; } naren VC++ programmer

      1 Reply Last reply
      0
      • A aaadetos

        Hi, im trying to use the specific value of an array in a computation in another function; but don't know how to set it up. In test(), i want to use the 6th value of C[] in the computation. How do i set this up please? #include "stdafx.h" #include const int size = 10; double A[size] = {0},B[size] = {0}, C[size],c,d; double PI = 3.141592653589793238462643383279502884197; void rah(double C[]) { for (int i=0;i

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        aaadetos wrote: In test(), i want to use the 6th value of C[] in the computation. How do i set this up please? double test()//how do i write this correctly? { rah(C); d = PI * rah(C[5]); } It appears that you are already using "the 6th value of C[] in the computation." What is it that you think is wrong? The code that I do see as wrong is when you are calling the rah() function. rah() is expecting a double array (i.e., C[]), yet you are calling it with a single double value (i.e., C[5]).


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        A 1 Reply Last reply
        0
        • D David Crow

          aaadetos wrote: In test(), i want to use the 6th value of C[] in the computation. How do i set this up please? double test()//how do i write this correctly? { rah(C); d = PI * rah(C[5]); } It appears that you are already using "the 6th value of C[] in the computation." What is it that you think is wrong? The code that I do see as wrong is when you are calling the rah() function. rah() is expecting a double array (i.e., C[]), yet you are calling it with a single double value (i.e., C[5]).


          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

          A Offline
          A Offline
          aaadetos
          wrote on last edited by
          #4

          Thanks a lot guys. The dilemma was to use one of the elements (the 6th) in the computation. I implemented test() in the following way: double test() { rah(C); d = PI * C[5]; return d; }

          D 1 Reply Last reply
          0
          • A aaadetos

            Thanks a lot guys. The dilemma was to use one of the elements (the 6th) in the computation. I implemented test() in the following way: double test() { rah(C); d = PI * C[5]; return d; }

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Why is d a global variable? Unless absolutely necesssary, that is very poor practice. In this instance, it makes no sense for test() to return d since it is already global. Either make d local to the test() function, or change test() to return nothing.


            "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups