Help not sure what I'm missing

Hey guys,
Just joined today, and since It's my first post. I'm not sure where to post this either in Beginner or here. anyway, I can't figure out how to turn 00:30am/pm to show as 12:30 am/pm . here's what I mean:


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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>


using namespace std

int main () { 

  int count = 0, // number of valid times entered
      newTime, // latest time entered
      lastTime = 0, // previous time entered
      gap, // current gap
      shortestGap, // the shortest gap
      longestGap, // the longest gap
      hours, // hours input
      minutes, // minutes input
      gapTotal = 0, // total of all gaps
      badCount = 0; // number of invalid times entered

  // get input from user
  cout << "Enter time in hours and minutes (99 99 to stop): ";
  cin >> hours >> minutes;
  
  // loop until user enters 99 99
  for (;;){
  	if (hours==99&&minutes==99){
  	
  	break;
  	}else{

	  // if time is crazy, output an error message
    if ((hours < 0) || (hours > 23) || (minutes < 0) || (minutes > 59)) {

      cout << "** Time ignored - hours and/or minutes invalid. **" << endl;
      badCount++;

    } else {

      newTime = (60 * hours) + minutes;

      // if time is before the previous one, output an error message
      if ( (newTime < lastTime) &&
           !((lastTime > 23 * 60) && (newTime < 60)) ) {
    
          cout << "** Time ignored - not >= previous time. **" << endl;
          badCount = badCount + 1;

      } else {
      	//converting 24hrs to 12hrs (12:30am//0:30am does not work)
if (hours == 00 && minutes == 00) {
		cout <<"valid time"<< " midnight"<<endl;
	} else if (hours == 12 && minutes == 00) {
		cout <<"valid time"<< " noon"<<endl;
	} else if (hours < 12) {
		
		cout <<"valid time"<<hours<<":"<<minutes<< "AM"<<endl;
		
	} else {
		hours=hours-12;
		cout <<"valid time"<<hours<<":"<<minutes<<"PM"<<endl;
	}
        // we have a good time

        if (count == 0) {

          // our very first time
          lastTime = newTime;
          count = 1; // we now have one time

        } else { 

          // not the first time, so there's a gap to calculate
          if (newTime < lastTime) {
            gap = (newTime + (24 * 60)) - lastTime;
          } else {
            gap = newTime - lastTime;
          } // end if
          
          // gap statistics: total; min and max
          gapTotal = + gap;
          if ((count == 1) || (gap < shortestGap)) {
            shortestGap = gap;
          }
          if ((count == 1) || (gap > longestGap)) {
            longestGap = gap;
          }
          lastTime = newTime;
          count++;

        } // end if

      } // end if

    } // end if}
    // get input from user
    cout << "Enter time in hours and minutes (99 99 to stop): ";
    cin >> hours >> minutes;
}
  } //end for

	  
	  
	

    
  // output results
  cout << endl << count << " valid times and " << badCount << " invalid times were entered." << endl;
  
  if (count < 2) {
    cout << "Fewer than 2 times were entered - no gaps to analayze.\n";
  } else {
    cout << "The shortest gap was " << shortestGap << " minutes long.\n"
         << "The longest gap was " << longestGap << " minutes long.\n"
         << "The average gap length was " << gapTotal / (count - 1.0)
         << " minutes." << endl;
  } // end if
  cout << endl;
  
  system ("PAUSE"); 
  return 0;
Last edited on
Your code is nearly unreadable. Please use the button marked '<>' at the right of the editor field to format it. Then try a preview to see whether other people like to read it.
Sorry, about that I fixed it, hopefully it's easier for people to read it now
Last edited on
Topic archived. No new replies allowed.