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. Function help [modified]

Function help [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-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.
  • P Offline
    P Offline
    planetx22
    wrote on last edited by
    #1

    updated code again, I think my function isn't working because when i return the value it doesnt look like its changed to celsius. Also, i only know how to print the value of myarray[0], how do i print each value entered? Thanks for the help. Code: // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; double c; double CheckCent(double c) { if (c>30) { return c - 32 /1.8; } return c; } // call this function to convert fahrenheit values into celsius (function name is CheckCent) int _tmain(int argc, _TCHAR* argv[]) { double myarray[51]; //double i; int flag; flag=1; int i; for(i = 0; i < 51 && flag == 1; i++) { // Loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; }// End for cout << "Number of elements in the array is: " << i; while(i < 50) { myarray[i]=CheckCent(myarray[i]); cout <<"\n"; cout << myarray[0]; return 0; } }

    B 1 Reply Last reply
    0
    • P planetx22

      updated code again, I think my function isn't working because when i return the value it doesnt look like its changed to celsius. Also, i only know how to print the value of myarray[0], how do i print each value entered? Thanks for the help. Code: // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; double c; double CheckCent(double c) { if (c>30) { return c - 32 /1.8; } return c; } // call this function to convert fahrenheit values into celsius (function name is CheckCent) int _tmain(int argc, _TCHAR* argv[]) { double myarray[51]; //double i; int flag; flag=1; int i; for(i = 0; i < 51 && flag == 1; i++) { // Loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; }// End for cout << "Number of elements in the array is: " << i; while(i < 50) { myarray[i]=CheckCent(myarray[i]); cout <<"\n"; cout << myarray[0]; return 0; } }

      B Offline
      B Offline
      Bram van Kampen
      wrote on last edited by
      #2

      You have the Source Code in Hand! Why not load it in your debugger and find out Where and Why it does not work. I am afraid that the reality is that writing code involves debugging. actually, it is an integral part of it. of all the members on this forum, I guess that few of the experts regularly write code that always compiles. Fewer write code that immediately performs as advertised. Those that do are continually worried about what their code 'might' do under adverse conditions. Unfortunately Debugging is part and parcel of writing code. This forum is NOT about doing the Debugging for you.

      LateNightsInNewry

      P 1 Reply Last reply
      0
      • B Bram van Kampen

        You have the Source Code in Hand! Why not load it in your debugger and find out Where and Why it does not work. I am afraid that the reality is that writing code involves debugging. actually, it is an integral part of it. of all the members on this forum, I guess that few of the experts regularly write code that always compiles. Fewer write code that immediately performs as advertised. Those that do are continually worried about what their code 'might' do under adverse conditions. Unfortunately Debugging is part and parcel of writing code. This forum is NOT about doing the Debugging for you.

        LateNightsInNewry

        P Offline
        P Offline
        planetx22
        wrote on last edited by
        #3

        Is this better? I kinda figured out how to use the function, but now I think thats where my problem lies. When i choose say 35 as the first value inputted, and then stop the loop, i dont get a correct celsius value but a number like 14.2323.2323. Here is my updated code, thanks. [code] // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; // call this function to convert fahrenheit values into celsius (function name is CheckCent) double CheckCent(double c) { if (c <= 30) return c; c=c-32/1.8; return c; } // main function int _tmain(int argc, _TCHAR* argv[]) { double myarray[51]; //double i; int flag; flag=1; int i; for(i = 0; i < 51 && flag == 1; i++) { // Loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; }// End for cout << "Number of elements in the array is: " << i; cout <<"\n"; for(int j=0;j<=i;j++) { myarray[j]=CheckCent(myarray[j]); cout << myarray[0]; } return 0; } [/code]

        R 1 Reply Last reply
        0
        • P planetx22

          Is this better? I kinda figured out how to use the function, but now I think thats where my problem lies. When i choose say 35 as the first value inputted, and then stop the loop, i dont get a correct celsius value but a number like 14.2323.2323. Here is my updated code, thanks. [code] // Computer Lab test.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include using namespace std; // call this function to convert fahrenheit values into celsius (function name is CheckCent) double CheckCent(double c) { if (c <= 30) return c; c=c-32/1.8; return c; } // main function int _tmain(int argc, _TCHAR* argv[]) { double myarray[51]; //double i; int flag; flag=1; int i; for(i = 0; i < 51 && flag == 1; i++) { // Loop to enter temperatures - pressing 1 continues, pressing 0 stops // cout << "Enter Temperature Reading:"; cin >>myarray[i]; cout << "Enter 1 to input more values, 0 to stop"; cin >>flag; }// End for cout << "Number of elements in the array is: " << i; cout <<"\n"; for(int j=0;j<=i;j++) { myarray[j]=CheckCent(myarray[j]); cout << myarray[0]; } return 0; } [/code]

          R Offline
          R Offline
          Rick York
          wrote on last edited by
          #4

          Here's my function : double FahrenheitToCelsius( double reading ) { return ( reading - 32.0 ) / 1.8; }

          B 1 Reply Last reply
          0
          • R Rick York

            Here's my function : double FahrenheitToCelsius( double reading ) { return ( reading - 32.0 ) / 1.8; }

            B Offline
            B Offline
            Bram van Kampen
            wrote on last edited by
            #5

            That's what I would have written too, but, This member appears not to know how to debug, or, that debugging is an integral part of code developmpent.

            LateNightsInNewry

            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