Output correct value
-
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 < -
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 <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 checkpointif (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) -
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 checkpointif (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)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 < -
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 <