My program reads water temperatures from a river as well as when the temps were recorded from an input file called "biodata.dat." Then the data is outputted in a file called "results.dat" (i havent added this results.dat part in my code but do know how to do it)
The input file looks like this:
2 // number of readings
200707211245 F70.5 // timestamp recored plus temp in Fahrenheit
200708220812 C19.97 // same but in Celsius

I am supposed to arrange the data so that the times and temperature readings(all temp readings must be in Celsius by formula) make sense, like this:
21.38C recorded on 07/21/2007 at 12:45
19.97C recorded on 08/22/2007 at 8:12.

my problem is that i dont know how to make the program only change the fahrenheit temperatures and not the celsius temperatures. how can i write something to tell them apart and use a formula to change specific temps?

btw, the formula from fahrenheit to celsius is C = 5 / 9 (F - 32)

this is the code i have so far:

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int main() {
	
	int numone;
	double degrees;
	string timestamp,
		   temp;
		   
	ifstream infile;
	infile.open("biodata.dat");
	if (!infile)
	{
			 cout << "Error opening biodata.dat\n";
			 system("pause");
	}
	

	
	infile >> numone;
	cout << "Number of recordings: "<<numone<<"\n\n";
	
	for (int i=1; i <= (numone); i++)
{
    
    cout<<i<<":  ";
        
	
		  infile >> timestamp;

		  string year = timestamp.substr(0,4);
		  string month = timestamp.substr(4,2);
		  string date = timestamp.substr(6,2);
		  string hour = timestamp.substr(8,2);
		  string minute = timestamp.substr(10,2);
		  cout << month << "/" << date << "/" << year << " "
			   << hour  << ":" << minute << "    Temp: ";
		  
		  infile >> temp; // F to C: (F - 32)(5/9)
		  
		  string unit = temp.substr(0,1);
		  string strtemp = temp.substr(1,temp.length());
		  double atof(char* strtemp);
		  
		  cout<<strtemp.c_str();
		  cout<<"\n";
		  
		  
}

cout<<"\n\n";	
system("pause");
return 0;   
}

heres the .dat (text) file:
2
200707211245 F70.5
200708220812 C19.97

Recommended Answers

All 2 Replies

so in the line 47,

if the line unit=="F" || then convert it to cel's.
does it sounds complicated?

void convert_F_to_C(string &); // you have to implement this function 
                               // do you need help on implementing this?

and on the line number 47,

if(unit=="F")
{ 
  convert_F_to_C(strtemp);
}

oh wow, i was just having a brain fart. that really would be easy.

thanks for the help :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.