I am a C++ learner , therefore, please do not judge me very much for not handling such a simple problem. I am trying to write a code (playing), which converts Fahrenheits into Celcius, and prints out both results on the screen. Like
F[0] = "", C=[0] = ""
and like that. But I cannot figure out how to make the program remember, print out the Fahreneheits as well. All I can successfully do is to print out only Celcius, using an array.
C[0] = " "
Can you please tell me how to handle this problem? Do I need to make, apparently I need, a multidimensional array?? My code is appended below.
Thanks!
// arrays as parameters
#include <iostream>
using namespace std;
const int MAX = 5;
int main ()
{
int array[MAX][MAX];
int i;
int j;
for (i=0; i < MAX; i++)
for (j=0; j < 1; j++)
{
int C, F;
cout << "Enter temperature in Fahrenheits:";
cin >> F;
C = (F - 32) * 5/9;
array[i][j] = C,F;
}
for (i = 0; i <= 4; i++)
for (j = 0; j <= 4; j++)
cout << "C[" << i << " " << j << "] = " << array[i][j] << endl; //Print out data into the screen
That is right. I am trying to make a table of converted values. I can do it only for one type of values. Here is an example for conversion of Fahrenheit to Celsius, but I do not see the Fahrenheit values, only Celsius.
// Program converts temperature from Fahrenheits into Celcius
// and writes the values into a file
//Created 05/05/2010
//by Kirill Pushkin
cout << "Enter temperature in fahrenheits:\n>";
cin >> fahrenheit;
celcius = (fahrenheit - 32) * 5/9; // conversion of temperature from Fahrenheits into Celcius
temperature[i] = celcius;
}
ofstream myfile; // command to open a file for writing with a name whatever you like
myfile.open ("/home/kirillpushkin/Documents/rootanalysis/C++_progs/examples/temperature.txt"); //creation of a file in a particular directory
for (i = 0; i <= 9; i++)
// Print temperature on the screen
// cout << "temperature[" << i << "] = " << temperature[i] << endl; //Print out data into the screen
myfile << "temperature[" << i << "] = " << temperature[i] << endl; //Writes data directly into a file
OK, we avoid providing complete code here but I'm going to do it since you need some perspective. Besides, I don't believe this is homework and you're putting in a lot of effort. Kudos for that! You're starting to get the idea but you are WAY over-complicating things.
Look at how simple this app can be (and I added the ability to specify a starting and ending temperature, plus a step so you don't have to see every temperature between them):
I suggest you try some of the more simple coding problems and get comfy with the basics. That way when you get to the tough stuff you'll have a solid foundation and things won't be so confusing. There are plenty of good beginner problems around here, just do a search.
Almost forgot: Please use code tags when you post. Select the code part(s) in your posts and click the <> Format: button on the right. It makes it SO much easier to read other peoples code and that makes it much more likely that you will get somebody to help you.