error check is not working properly

okay so i have an input file and it is filled with data like so

2
200708211245 F70.5
200707210821 C19.97

I need to error check so when a negative Celcius temp or a letter that is not F or C is in the program it terminates. The code I have right now does not show up if I change the letters or make it negative in the input file so I was just curious why.






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

#include <iostream>
#include <fstream>
#include <cstring>
#include <iomanip>
#include <cmath>

using namespace std;


double TemperatureConversion(double);

void printTimeStamp(ofstream &fout, char);
int main()
{
   const int DATE_SIZE = 13,
          TEMP_SIZE = 7;

    int num_of_temp_readings = 0,
        loop_count = 0;

    char date_arr[DATE_SIZE];
    char temp_arr[TEMP_SIZE];

    double temperature = 0.0;
    double total = 0.0;
    double average = 0.0;
    //temperature2;






    ifstream fin;
    fin.open("biodata.dat.txt");

    if(!fin)
    {
        cout << endl << endl
             << "Program terminated!" << endl << endl
             << "input failed to open." << endl;
             return -1;
    }

    ofstream fout;
    fout.open("Filtered_biodata.dat");

    if(!fout)
    {
        cout << endl << endl
             << "Program terminated!" << endl << endl
             << "Output failed to open." << endl;
            return -2;
    }

fout << "BIODATA Formatted Ouput "<< endl << endl;


    fin >> num_of_temp_readings;

    for(loop_count; loop_count < num_of_temp_readings; ++loop_count)
    {
        fin >> date_arr >> temp_arr;

        if (temp_arr[1] == '-')
            {
             cout << "Values cannot be negative "
                  << "terminating the program" << endl;

                return -3;
            }


        if(temp_arr[0] != 'F' && temp_arr[0] != 'C')
            {
            cout << "Temperature measurement is not valid. "
                 << "Unit is not recognized. Must be F or C" << endl
                 << "Terminating the Program! " << endl;

                 return -4;
            }



       // printTimeStamp(fout , date_arr);
    }


    fin.close();
    fout.close();

    return 0;
}


ignore the function prototypes at beginning
Topic archived. No new replies allowed.