473,769 Members | 2,382 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Temperature Conversion Program - Still a Rookie

Hey Everyone~
I'm still a C++ Rookie so please bear with me on this.
I'm doing a temperature conversion program with prototype functions.
Basicly, I was wondering if some of you would take a look at my code
and critique it for me. I'm mostly concerned with how prototype
functions work and if I designed them correctly in my code.
Your participation would be greatly appreciated!

My Code:

#include "stdafx.h"
#include <iostream>
#include <cstdlib>

double FahrenheittoCel sius(double)= 0.0; //Function Prototype
double CelsiustoFahren heit(double)= 0.0;

int _tmain(int argc, _TCHAR* argv[])
{
double tempFahrenheit, tempCelsius;
double temp;
char f;
char c;
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius?"; // If user does not specify f or c
ask them
if (temp == f)
{
c = FahrenheittoCel sius;
cout << f " degrees Fahrenheit is" c " degrees celsius ";
cout << " Continue? ";

else
f = CelsiustoFahren heit;
cout << c " degrees Celsius is " f " degrees Fahrenheit ";
cout << " Continue? ";

}
return temp;
}
double FahrenheitoCels ius (double f)
{
return (f - 32) * (5.0/9);
}
double CelsiustoFahren heit (double c)
{
return (9/5.0 * c) + 32;
}

Mar 31 '07
21 4266
Ian Collins wrote:
James Kanze wrote:
--

Please fix this - it's a pain to have to keep manually trimming your
signature.
Heh, I was going to mention that as well. James, your .sig separator is
missing a character. It should be "-- " (dash dash space).


Brian
Apr 2 '07 #21
Thank you guys!
Your criticism and suggestions helped me! I appreciate you guys taking
the time to critique me! I got it to work finally!

And I found this funny....
"He made no mention of a complier, just that the code wouldn't
compile
without it. On my system, it won't compile with it!

--
Ian Collins. "

Hahaha...I'm a girl. So..."She made no mention....". ;) Just thought
I'd let ya know Ian!

But, again, I appreciate all of your help!

~Ashley~

So, here is the final code:
// Temperature.cpp : Defines the entry point for the console
application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;

float FahrenheittoCel sius(float f); //Function Prototype
float CelsiustoFahren heit(float c);
float result = 0;
int main()
{
float tempFahrenheit = 0;
float tempCelsius = 0;
float temp = 0;
char corf = 'f';
char yorn = 'y';

cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius? ";
cin >corf;
if (corf == 'f')
{
FahrenheittoCel sius(temp);
cout << temp << " degrees Fahrenheit is" << result << " degrees
celsius " << endl;
}
else if (corf == 'c')
{
CelsiustoFahren heit(temp);
cout << temp << " degrees Celsius is " << result << " degrees
Fahrenheit" << endl;
}

cout << " Continue? Y or N ";
cin >yorn;
while (yorn == 'y')
{
cout << " Enter the Temperature: "; //Prompt user to enter temp
cin >temp;
cout << " Fahrenheit or Celsius? ";
cin >corf;

if (corf == 'f')
{
FahrenheittoCel sius(temp);
cout << temp << " degrees Fahrenheit is" << result << " degrees
celsius " << endl;
}
else if (corf == 'c')
{
CelsiustoFahren heit(temp);
cout << temp << " degrees Celsius is " << result << " degrees
Fahrenheit" << endl;
}
cout << " Continue? Y or N ";
cin >yorn;
}

while (yorn != 'n')

return 0;
}
float FahrenheittoCel sius (float f)
{
result = 5.0 / 9.0 * (f - 32);
return result;
}
float CelsiustoFahren heit (float c)
{
result = (9.0 / 5.0 * c) + 32;
return result;
}




Apr 3 '07 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7848
by: Derek Ross | last post by:
Hello, Say I have a server that's saving the CPU temperature to 'temperature.js' once a second. The contents of the file is one single line: var temperature = "35.5"; And it changes as the temperature changes.
1
12134
by: deanfamily11 | last post by:
I'm trying to have this program do a simple temperature conversion from Fahrenheit to Celsius. I have confirmed that the other variable is receiving and calculating the conversion, but it is just outputting as "0". Any thoughts? (Code is below) #include <iostream> #include <iomanip> using namespace std;
5
32498
by: anthony | last post by:
One the computer I am programmig I could see the CPU temperature in the BIOS, is there a system DLL in VB.NET that I can call to display the temperature in my software? Thanks!
7
4869
by: alexandre_irrthum | last post by:
Hi there, I am trying to use pyserial to read data from a temperature logger device (T-logger). T-logger is based on the DS1615 temperature recorder chip (Dallas Semiconductor). According to the DS1615 docs, writing to the chip is performed one byte at a time. To read from the chip, one must issue the "read page" command (33h), followed by the two-byte address of the requested page (pages are 32 bytes long). After receiving this, the...
1
3200
by: pollardw | last post by:
i have written a small program to convert Fahrenheit to Celsius and I have a minor problem. Here is the code what do i need to change to get it to work? /* Convert Fahrenheit to Celsius */ #include <iostream> #include <iomanip> #include <string>
4
2343
by: arnuld | last post by:
this is my final code. Can you folks advise some improvements for making this programme better? BTW, i aways compile my programme with this cmmand on Linux: g++ -ansi -pedantic -Wall -Wextra file.cpp // a programme that converts Fahrenheit temperature // to Celcius (in range 0 -
16
4428
by: Brigitte Behrmann | last post by:
I am absolutely stuck with this one. I have to create a temperature conversion calculator that rounds the resulting temperature to the nearest whole number & vice versa. The result must be displayed in a window alert. The given formula is (Fahrenheit_temp - 32) * .55 The only tip/clue I have is to use var tempInCelcius = (document.Converter.fahrenheit.value - 32) * .55; var tempInFahrenheit = (document.Converter.celcius.value * 1.8) + 32 ...
1
3336
by: vbfrnd | last post by:
I need to write a program where I have to convert a temp provided by user to celcius or farenheit and vice versa. I am using text boxes to get the temp in degrees but when I am trying to convert the string to double by CDbl it is showing error while debugging.. I will be thankful If anyone can provide answer..
25
4903
by: kid joe | last post by:
Hi, Is it normal for the temperature of your CPU to increase as time goes on? I've got an Athlon XP 2100+ and I see that the temp is now at 51C where it used to be around 42 to 44. Anyone have any ideas?
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.