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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
void twtotv (int &hours, int &minutes);
void tvtotw (int &hours, int &minutes);
void menu (string &choice);
int main(){
int hours;
int minutes;
string choice;
menu(choice);
getchar();
getchar();
return 0;
}
void twtotv (int &hours, int &minutes){
cout<<"You have chosen 24 hour time -> 12 hour time"<<endl;
cout<<endl;
again:
cout<<"Please enter a valid hour value, ex. 0,1,2,3...23"<<endl;
cout<<endl;
cin>>hours;
if (hours>=24){
cout<<"That's not possible, Try again"<<endl;
cout<<endl;
goto again;
}
cout<<"You have entered "<<hours<<" o'clock "<<endl;
cout<<endl;
againmin:
cout<<"Please enter a valid minutes value, ex. 00,01,02,03...59"<<endl;
cout<<endl;
cin>>minutes;
if (minutes>59){
cout<<"That's not possible, Try again"<<endl;
cout<<endl;
goto againmin;
}
if (minutes<10){
cout<<"You have entered "<<hours<<":"<<"0"<<minutes<<endl;
cout<<endl;
}
if (minutes>10){
cout<<"You have entered "<<hours<<":"<<minutes<<endl;
cout<<endl;
}
if (hours<12&&minutes<10&&minutes==0&&hours==0){
hours=hours+12;
cout<<"The converted 12 hour time is "<<hours<<":"<<"0"<<minutes<<" AM"<<endl;
cout<<endl;
}
if (hours<12&&minutes<10&&minutes!=0){
cout<<"The converted 12 hour time is "<<hours<<":"<<minutes<<" AM"<<endl;
cout<<endl;
}
if (hours<12&&minutes>=10){
cout<<"The converted 12 hour time is "<<hours<<":"<<minutes<<" AM"<<endl;
cout<<endl;
}
if (hours==12&&minutes<10&&minutes!=0){
cout<<"The converted 12 hour time is "<<hours<<":"<<"0"<<minutes<<" PM"<<endl;
cout<<endl;
}
if (hours==12&&minutes>=10){
cout<<"The converted 12 hour time is "<<hours<<":"<<minutes<<" PM"<<endl;
cout<<endl;
}
if (hours>12&&minutes<10){
hours=hours-12;
cout<<"The converted 12 hour time is "<<hours<<":"<<"0"<<minutes<<" PM"<<endl;
cout<<endl;
}
if (hours>12&&minutes>=10){
hours=hours-12;
cout<<"The converted 12 hour time is "<<hours<<":"<<minutes<<" PM"<<endl;
cout<<endl;
}
nice:
cout<<"Need to convert again? Type 1 for Yes or 2 for No"<<endl;
cout<<endl;
int again;
string choice;
cin>>again;
switch (again){
case 1 : menu(choice);
break;
case 2 : exit (1);
break;
default : "That doesn't work, try again";
goto nice;
}
}
void tvtotw (int &hours, int &minutes){
cout<<"You have chosen 12 hour time -> 24 hour time"<<endl;
cout<<endl;
againtwo:
cout<<"Please enter a valid hour value, ex. 1,2,3...12"<<endl;
cout<<endl;
cin>>hours;
if (hours>24){
cout<<"That's not possible, Try again"<<endl;
cout<<endl;
goto againtwo;
}
if (hours>24&&hours!=0){
cout<<"That's not possible, Try again"<<endl;
cout<<endl;
goto againtwo;
}
if (hours==0){
cout<<"That's not possible, Try again"<<endl;
cout<<endl;
goto againtwo;
}
cout<<"You have entered "<<hours<<" o'clock "<<endl;
cout<<endl;
againminutes:
cout<<"Please enter a valid minutes value, ex. 00,01,02,03...59"<<endl;
cout<<endl;
cin>>minutes;
if (minutes>59){
cout<<"That's not possible, Try again"<<endl;
cout<<endl;
goto againminutes;
}
AMPMagain:
cout<<"Please enter AM (ante meridian) or PM (post meridian)"<<endl;
cout<<endl;
cout<<"*** Reminder, AM and PM MUST be CAPITAL ***"<<endl;
cout<<endl;
string ampm;
cin>>ampm;
if (ampm!="AM"&&m!="PM"){
cout<<"That won't work, try again"<<endl;
cout<<endl;
goto AMPMagain;
}
if (minutes<10){
cout<<"You have entered "<<hours<<":"<<"0"<<minutes<<" "<<ampm<<endl;
cout<<endl;
}
if (minutes>=10){
cout<<"You have entered "<<hours<<":"<<minutes<<" "<<ampm<<endl;
cout<<endl;
}
if (hours<=12&&minutes<10){
hours=hours+12;
cout<<"The converted 24 hour time is "<<hours<<":"<<"0"<<minutes<<" "<<ampm<<endl;
cout<<endl;
}
if (hours<=12){
hours=hours+12;
cout<<"The converted 24 hour time is "<<hours<<":"<<minutes<<" "<<ampm<<endl;
cout<<endl;
}
cout<<"Need to convert again? Type 1 for Yes or 2 for No"<<endl;
cout<<endl;
int again;
string choice;
wow:
cin>>again;
switch (again){
case 1 : menu(choice);
break;
case 2 : exit(1);
default : cout<<"That wont work, try again"<<endl;
break;
goto wow;
}
}
void menu (string &choice){
int hours;
int minutes;
cout<<"Welcome to the time converter, where we convert 12 hour time to 24 hour time,"<<endl;
cout<<"and vice versa!"<<endl;
cout<<endl;
cout<<"So which would you like ..."<<endl;
cout<<endl;
retry:
cout<<"Enter 12 for ***12 hour time -> 24 hour time***"<<endl;
cout<<endl;
cout<<"Enter 24 for ***24 hour time -> 12 hour time***"<<endl;
cout<<endl;
cout<<"At any time you can type quit to exit the program"<<endl;
cout<<endl;
cin>>choice;
if (choice=="12"){
tvtotw(hours,minutes);
}
if (choice=="24"){
twtotv(hours,minutes);
}
if (choice=="quit"){
exit(1);
}
if (choice!="12"&&choice!="24"&&choice!="quit"){
cout<<"INVALID INPUT, TRY AGAIN"<<endl;
cout<<endl;
goto retry;
}
}
|