| | |
Help with a seemingly simple program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2006
Posts: 7
Reputation:
Solved Threads: 0
Hello, I've been working on this problem for a while, its a program that needs to convert military time to civilian time from an input file using a user-defined function. Then the program must find the maximum temperature and list the temperature and the time at which it occurs.
My program runs, but my while loop exits after the first line of data from the infile. Its been driving me crazy, any idea what I'm doing wrong?
Thanks for any help!
My program runs, but my while loop exits after the first line of data from the infile. Its been driving me crazy, any idea what I'm doing wrong?
c Syntax (Toggle Plain Text)
#include "stdafx.h" #include <iostream> #include <fstream> using namespace std; bool convert(int , int& , int&); int _tmain(int argc, _TCHAR* argv[]) { ifstream infile( "hw3_input.txt" ); ofstream outfile( "hw3_output.out" ); int time; int mil_time; // Given military time int hour; int minute; int temperature; int MaxTimeTemp; int MaxTemp; while (!infile.fail()){ infile >> mil_time; time = mil_time; MaxTimeTemp = time; infile >> temperature; temperature = temperature; MaxTemp = temperature; if (temperature > MaxTemp){ MaxTemp = temperature; MaxTimeTemp = mil_time; } } bool PM = convert(MaxTimeTemp , hour , minute); if (PM){ cout << "The maximum temperature is " << MaxTemp << " and it occurs at " << hour << ":" << minute << " PM" << endl; } else { cout << "The maximum temperature is " << MaxTemp << " and it occurs at " << hour << ":" << minute << " AM" << endl; } infile.close(); outfile.close(); return 0; } bool convert(int mil_time, int& hour_1 , int& minute_1){ hour_1 = mil_time / 100; minute_1 = mil_time % 100; if (hour_1 > 12){ hour_1 = hour_1 - 12; } return mil_time >= 1200; }
Thanks for any help!
Last edited by Schmitty27; Nov 1st, 2006 at 4:14 pm.
•
•
Join Date: Nov 2006
Posts: 7
Reputation:
Solved Threads: 0
Sure thing, I was thinking I should have done that.
0845 34.2 32.2 101.5
0922 38.8 32.2 112.1
1047 44.8 32.4 142.5
1159 51.3 32.0 152.0
1215 55.5 31.8 166.5
1329 61.3 31.9 186.5
1441 67.5 32.3 208.0
1523 72.1 32.8 226.2
1656 76.8 32.5 256.4
1738 83.5 32.7 286.9
1800 88.9 33.0 318.6
The values from left to right are the military time, temperature, pressure and volume. I am currently just concerned with the temperature, and plan on doing the other two once I manage to get this thing working.
0845 34.2 32.2 101.5
0922 38.8 32.2 112.1
1047 44.8 32.4 142.5
1159 51.3 32.0 152.0
1215 55.5 31.8 166.5
1329 61.3 31.9 186.5
1441 67.5 32.3 208.0
1523 72.1 32.8 226.2
1656 76.8 32.5 256.4
1738 83.5 32.7 286.9
1800 88.9 33.0 318.6
The values from left to right are the military time, temperature, pressure and volume. I am currently just concerned with the temperature, and plan on doing the other two once I manage to get this thing working.
I would personally read the file in one line at a time and then divide that line into you following attributes, temp, time, pressure etc.
Finding a maximum is simple
int max = 1000000;
int temperature = 0;
if ( currentValue > max )
{
max = currentValue
temperature = currentTemperature
//move to next line
}
Make any sense? Need any code samples?
Finding a maximum is simple
int max = 1000000;
int temperature = 0;
if ( currentValue > max )
{
max = currentValue
temperature = currentTemperature
//move to next line
}
Make any sense? Need any code samples?
*Voted best profile in the world*
![]() |
Similar Threads
- Need advice & help with a very simple program (IT Professionals' Lounge)
- Erroneus outputs in string manipulation simple program (C++)
- Simple C++ program terminate prematurely (C++)
- I am a girl doing my 1st simple program (C)
Other Threads in the C++ Forum
- Previous Thread: C/C++ Calender Program
- Next Thread: Pulling data from vectors
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






