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. Output correct value

Output correct value

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structures
4 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

    My program works fine if the temperature entered is above 30(say 100).. it will perform the calculations and output the result. I need it to also output the number if it is below 30 (if i enter 29, it outputs 29) but i can't get it to output anything. Thnx for the advice.

    // Computer Lab test.cpp : Program that asks for temperature inputs,
    // ensures input is in centigrade, and outputs # of arrays + corrected temp

    // Andrew Stewart CMPT 201

    #include "stdafx.h"
    #include using namespace std;

    float CheckCent(float c) // Function to convert user values into centigrade(celsius) <- function named CheckCent
    {
    if (c > 30.0)
    {
    c=(c-32.0)/(1.80); return c; // formula for fahrenheit to celsius(centigrade)
    }
    return c;
    }
    int _tmain(int argc, _TCHAR* argv[]) // Main function
    {
    float myarray[50]; // declare array from 0-49 values
    int flag; // counter for loop
    flag=1;
    int i; // number of arrays
    for(i = 0; i < 50 && flag == 1; i++)
    {
    cout << "Enter Temperature Reading:";
    cin >>myarray[i];
    cout << "Enter 1 to input more values, 0 to stop";
    cin >>flag;
    }// End for
    cout << "\n\nNumber of elements in the array is: " << i <30.0)
    {
    myarray[j]=CheckCent(myarray[j]);
    cout <<"The corrected value is: ";
    cout <

    P 1 Reply Last reply
    0
    • P planetx22

      My program works fine if the temperature entered is above 30(say 100).. it will perform the calculations and output the result. I need it to also output the number if it is below 30 (if i enter 29, it outputs 29) but i can't get it to output anything. Thnx for the advice.

      // Computer Lab test.cpp : Program that asks for temperature inputs,
      // ensures input is in centigrade, and outputs # of arrays + corrected temp

      // Andrew Stewart CMPT 201

      #include "stdafx.h"
      #include using namespace std;

      float CheckCent(float c) // Function to convert user values into centigrade(celsius) <- function named CheckCent
      {
      if (c > 30.0)
      {
      c=(c-32.0)/(1.80); return c; // formula for fahrenheit to celsius(centigrade)
      }
      return c;
      }
      int _tmain(int argc, _TCHAR* argv[]) // Main function
      {
      float myarray[50]; // declare array from 0-49 values
      int flag; // counter for loop
      flag=1;
      int i; // number of arrays
      for(i = 0; i < 50 && flag == 1; i++)
      {
      cout << "Enter Temperature Reading:";
      cin >>myarray[i];
      cout << "Enter 1 to input more values, 0 to stop";
      cin >>flag;
      }// End for
      cout << "\n\nNumber of elements in the array is: " << i <30.0)
      {
      myarray[j]=CheckCent(myarray[j]);
      cout <<"The corrected value is: ";
      cout <

      P Offline
      P Offline
      PS Codeproj
      wrote on last edited by
      #2

      In your program you are allowing only the input value thats greater than 30 for the conversion. if(myarray[j]>30.0) And in CheckCent function also you are having the checkpoint if (c > 30.0) Remove them. So that it work for other values too. And check your conversion factor too. Below is the formula for converting Faren... to Celsius (Tc = (5/9)*(Tf-32); Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit)

      P 1 Reply Last reply
      0
      • P PS Codeproj

        In your program you are allowing only the input value thats greater than 30 for the conversion. if(myarray[j]>30.0) And in CheckCent function also you are having the checkpoint if (c > 30.0) Remove them. So that it work for other values too. And check your conversion factor too. Below is the formula for converting Faren... to Celsius (Tc = (5/9)*(Tf-32); Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit)

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

        This is the output I get from my program now, but after it ouputs the correct value it says outputs another number like -12323e.6 and then says "Program Complete!" again. How do i get rid of this second output? Im also getting an error message - line [14] conversion from double to float, possible loss of data. Thanks.

        // Computer Lab test.cpp : Program that asks for temperature inputs,
        // ensures input is in centigrade, and outputs # of arrays + corrected temp

        // Andrew Stewart CMPT 201

        #include "stdafx.h"
        #include using namespace std;

        float CheckCent(float c) // Function to convert user values into centigrade(celsius) <- function named CheckCent
        {
        if(c>30)
        {
        c=(c-32)/(1.80); return c; // formula for fahrenheit to celsius(centigrade)
        }
        else return c;
        }
        int _tmain(int argc, _TCHAR* argv[]) // Main function
        {
        float myarray[50]; // declare array from 0-49 values
        int flag; // counter for loop
        flag=1;
        int i; // number of arrays
        for(i = 0; i < 50 && flag == 1; i++)
        {
        cout << "Enter Temperature Reading:";
        cin >>myarray[i];
        cout << "Enter 1 to input more values, 0 to stop";
        cin >>flag;
        }// End for
        cout << "\n\nNumber of elements in the array is: " << i <

        J 1 Reply Last reply
        0
        • P planetx22

          This is the output I get from my program now, but after it ouputs the correct value it says outputs another number like -12323e.6 and then says "Program Complete!" again. How do i get rid of this second output? Im also getting an error message - line [14] conversion from double to float, possible loss of data. Thanks.

          // Computer Lab test.cpp : Program that asks for temperature inputs,
          // ensures input is in centigrade, and outputs # of arrays + corrected temp

          // Andrew Stewart CMPT 201

          #include "stdafx.h"
          #include using namespace std;

          float CheckCent(float c) // Function to convert user values into centigrade(celsius) <- function named CheckCent
          {
          if(c>30)
          {
          c=(c-32)/(1.80); return c; // formula for fahrenheit to celsius(centigrade)
          }
          else return c;
          }
          int _tmain(int argc, _TCHAR* argv[]) // Main function
          {
          float myarray[50]; // declare array from 0-49 values
          int flag; // counter for loop
          flag=1;
          int i; // number of arrays
          for(i = 0; i < 50 && flag == 1; i++)
          {
          cout << "Enter Temperature Reading:";
          cin >>myarray[i];
          cout << "Enter 1 to input more values, 0 to stop";
          cin >>flag;
          }// End for
          cout << "\n\nNumber of elements in the array is: " << i <

          J Offline
          J Offline
          jeron1
          wrote on last edited by
          #4

          Try this for(int j = 0; j < i; j++) instead of this for(int j = 0; j <= i; j++) -- modified at 10:22 Monday 9th April, 2007

          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