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. messy function that calculates values

messy function that calculates values

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 6 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.
  • B Offline
    B Offline
    bhangie
    wrote on last edited by
    #1

    Hi before any one start slandering me about this code i did not write it(DID NOT). It is a Question :) well kinda(HW) and i realy need help i wont take any offence if i whas told i'm stupid, I just need help. The question is(from Lecturer) (i) Rewrite the following piece of code correcting all the problems found(Given the followng code) void CalculateValues(const int &a, float *b, int &c) { d = 20.4; if(*a = 0) { *a += 1; c = a + d; } else { b = c / d; c = a - b + d; } } Included a Hint: if a=4, b=0.0, c=5 When funct return should be: a=4, b=0.25 and c=24.15. Need help with the prototype and calculations PLEASE:( Many Thanks.

    T W M D V 5 Replies Last reply
    0
    • B bhangie

      Hi before any one start slandering me about this code i did not write it(DID NOT). It is a Question :) well kinda(HW) and i realy need help i wont take any offence if i whas told i'm stupid, I just need help. The question is(from Lecturer) (i) Rewrite the following piece of code correcting all the problems found(Given the followng code) void CalculateValues(const int &a, float *b, int &c) { d = 20.4; if(*a = 0) { *a += 1; c = a + d; } else { b = c / d; c = a - b + d; } } Included a Hint: if a=4, b=0.0, c=5 When funct return should be: a=4, b=0.25 and c=24.15. Need help with the prototype and calculations PLEASE:( Many Thanks.

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      bhangie wrote: *a += 1; false, a is not a pointer secondly, it is declared as a const, you cannot write into it. bhangie wrote: b = c / d; b is a float*, you so should write *b in your code when using it. or define it as a float&.


      TOXCCT >>> GEII power

      1 Reply Last reply
      0
      • B bhangie

        Hi before any one start slandering me about this code i did not write it(DID NOT). It is a Question :) well kinda(HW) and i realy need help i wont take any offence if i whas told i'm stupid, I just need help. The question is(from Lecturer) (i) Rewrite the following piece of code correcting all the problems found(Given the followng code) void CalculateValues(const int &a, float *b, int &c) { d = 20.4; if(*a = 0) { *a += 1; c = a + d; } else { b = c / d; c = a - b + d; } } Included a Hint: if a=4, b=0.0, c=5 When funct return should be: a=4, b=0.25 and c=24.15. Need help with the prototype and calculations PLEASE:( Many Thanks.

        W Offline
        W Offline
        WoutL
        wrote on last edited by
        #3

        void CalculateValues(int &a, float &b, int &c) { d = 20.4; if(0 == a) { a += 1; c = a + d; } else { b = c / d; c = a - b + d; } } Wout Louwers

        1 Reply Last reply
        0
        • B bhangie

          Hi before any one start slandering me about this code i did not write it(DID NOT). It is a Question :) well kinda(HW) and i realy need help i wont take any offence if i whas told i'm stupid, I just need help. The question is(from Lecturer) (i) Rewrite the following piece of code correcting all the problems found(Given the followng code) void CalculateValues(const int &a, float *b, int &c) { d = 20.4; if(*a = 0) { *a += 1; c = a + d; } else { b = c / d; c = a - b + d; } } Included a Hint: if a=4, b=0.0, c=5 When funct return should be: a=4, b=0.25 and c=24.15. Need help with the prototype and calculations PLEASE:( Many Thanks.

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #4

          homework ... hmmm ... ;)


          Maximilien Lincourt Your Head A Splode - Strong Bad

          1 Reply Last reply
          0
          • B bhangie

            Hi before any one start slandering me about this code i did not write it(DID NOT). It is a Question :) well kinda(HW) and i realy need help i wont take any offence if i whas told i'm stupid, I just need help. The question is(from Lecturer) (i) Rewrite the following piece of code correcting all the problems found(Given the followng code) void CalculateValues(const int &a, float *b, int &c) { d = 20.4; if(*a = 0) { *a += 1; c = a + d; } else { b = c / d; c = a - b + d; } } Included a Hint: if a=4, b=0.0, c=5 When funct return should be: a=4, b=0.25 and c=24.15. Need help with the prototype and calculations PLEASE:( Many Thanks.

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

            bhangie wrote: d = 20.4; This variable has not been declared. I assume it is a double (or float). bhangie wrote: if(*a = 0) Variable a is being passed as a reference to CalculateValues(). Therefore, *a is an incorrect reference since a pointer was not passed to CalculateValues(). bhangie wrote: c = a + d; Different types are being operated on here. You'll probably need to cast the float "down to" an int. bhangie wrote: c = a - b + d; Again, different types are being operated on here. Variable b is a pointer, whereas a and d are not.


            "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

            1 Reply Last reply
            0
            • B bhangie

              Hi before any one start slandering me about this code i did not write it(DID NOT). It is a Question :) well kinda(HW) and i realy need help i wont take any offence if i whas told i'm stupid, I just need help. The question is(from Lecturer) (i) Rewrite the following piece of code correcting all the problems found(Given the followng code) void CalculateValues(const int &a, float *b, int &c) { d = 20.4; if(*a = 0) { *a += 1; c = a + d; } else { b = c / d; c = a - b + d; } } Included a Hint: if a=4, b=0.0, c=5 When funct return should be: a=4, b=0.25 and c=24.15. Need help with the prototype and calculations PLEASE:( Many Thanks.

              V Offline
              V Offline
              vividtang
              wrote on last edited by
              #6

              #include #include using namespace std; void CalculateValues(const int &a, double *b, double &c) //c only can be double,if float,then *b=c/d how to transfer from float to double {c=5; double d = 20.4;//only double. if(a == 0) { //*a += 1;//error c = a + d; } else { *b = c / d; c =a - *b +d; cout<<"a="<

              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