Hey I am trying to make a temp converter, but I am having some trouble with getting my difference function to work I was wondering if anyone could give me a bit of a hand quite new to this. This is what I have so far.
// Question 0.cpp : Defines the entry point for the console application.
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;
// Farhenheit Table Function
double Farhenheit(int x)
{
double Farhenheit;
for (int i = 0 ; i <= 100 ; i++)
{
Farhenheit = ( x *9/5 ) +32;
}
return Farhenheit;
}
//Approx Function
double Approx(int x)
{
double Approx;
for (int i = 0 ; i <= 100 ; i++)
{
Approx = (x*2)+30;
}
return Approx;
}
// Differnce Function
int Difference(int x)
{
double Difference;
for (int i = 0 ; i <= 100 ; i++)
{
Difference = Farhenheit-Approx;
}
return Difference;
}
// Main Function
int main()
{
cout << "This will display the farhenheit to celcius conversion table from 0-100.\n\n";
cout << "Celcius \t Actual Farhenheit \t Approx \t Difference\n\n";
This is wrong on so many levels.
1) Most loops are useless. For example:
1 2 3
for (int i = 0 ; i <= 100 ; i++) {
Farhenheit = ( x *9/5 ) +32;
}
You are counting the same value 101 times.
2)x*9/5 it is better to use doubles if you are not doing integer division: x*9.0/5.0. It works fine here, but you can run into some unpleasant behavior later.
3) In Difference() you should call Farhenheit and Approx as functions: Difference = Farhenheit(x)-Approx(x);