Need help putting this together.

I need help putting my time converter and measurement converter together, i know what to do, simply create a menu that either calls the time conversion or the measure conversion, but when i tried it and it kept closing off, no errors whatsoever, so can someone help me put this together in one propgram? (This is simple C++ so nothing out of the ordinary that i can't understand please ^^)



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"&&ampm!="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;
                                                     }
}

Last edited on
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
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
void measuremenu (int &choices);
void FItoMC (float &feet, float &choice);
void MCtoFI (float &meters, float &centimeters);
int main(){
    float feet;
    float inches;
    float meters;
    float centimeters;
    int choices;
    measuremenu(choices);    
    getchar();
    getchar();
    return 0;
}
void measuremenu (int &choices){
     float feet;
     float inches;
     float meters;
     float centimeters;
     cout<<"Hello, Welcome to the Measurement Converter Program"<<endl;
     cout<<endl;
     cout<<"Please enter a number corresponding to your conversion choice"<<endl;
     cout<<endl;
     repeat:
     cout<<"1. Feet and Inches -----> Meters and Centimeters"<<endl;
     cout<<endl;
     cout<<"2. Meters and Centimeters -----> Feet and Inches"<<endl;
     cout<<endl;
     cin>>choices;
     if (choices!=1 && choices!=2){
                   cout<<"That is not a valid choice, its either 1 or 2, TRY AGAIN"<<endl;
                   cout<<endl;
                   goto repeat;
                   }
     if (choices==1){
                   cout<<"You have chosen Feet and Inches -----> Meters and Centimeters"<<endl;
                   cout<<endl;
                   FItoMC(feet,inches);
                   }
     if (choices==2){
                    cout<<"You have chosen Meters and Centimeters -----> Feet and Inches"<<endl;
                    cout<<endl;
                    MCtoFI(meters,centimeters);
                    }
                    }
void FItoMC (float &feet, float &inches){
     cout<<"Please enter a valid Feet value"<<endl;
     cout<<endl;
     cin>>feet;
     cout<<"You entered "<<feet<<" Feet"<<endl;
     cout<<endl;
     cout<<"Please enter a valid Inch value"<<endl;
     cout<<endl;
     cin>>inches;
     cout<<"You entered "<<inches<<" Inches"<<endl;
     cout<<endl;
     cout<<"So your input is "<<feet<<" Feet and "<<inches<<" Inches"<<endl;
     cout<<endl;
     feet=.3048*feet;
     inches=2.54*inches;
     float meters;
     float centimeters;
     meters=feet;
     centimeters=inches;
     cout<<"The converted measurements are "<<meters<<" Meters and "<<centimeters<<" Centimeters"<<endl;
     cout<<endl;
     int onceagain;
     three:
     int choice;
     cout<<"Need to convert again? Type 1 for Yes or 2 for No"<<endl;
     cin>>onceagain;
     switch (onceagain){
            case 1 : measuremenu(choice);
            break;
            case 2 : exit(1);
            break;
            default : "That doesn't work, try again";
            goto three;
     }
     }
void MCtoFI (float &meters, float &centimeters){
     cout<<"Please enter a valid Meter(s) value"<<endl;
     cout<<endl;
     cin>>meters;
     cout<<"You entered "<<meters<<" Meter(s)"<<endl;
     cout<<endl;
     cout<<"Please enter a valid Centimeter(s) value"<<endl;
     cout<<endl;
     cin>>centimeters;
     cout<<"You entered "<<centimeters<<" Centimeter(s)"<<endl;
     cout<<endl;
     cout<<"So your input is "<<meters<<" Meter(s) and "<<centimeters<<" Centimeter(s)"<<endl;
     cout<<endl;
     meters=3.280839895*meters;
     centimeters=0.3937007874*centimeters;
     float feet;
     float inches;
     feet=meters;
     inches=centimeters;
     cout<<"The converted measurements are "<<feet<<" Feet and "<<inches<<" Inches"<<endl;
     cout<<endl;
     int anotheragain;
     four:
     int choice;
     cout<<"Need to convert again? Type 1 for Yes or 2 for No"<<endl;
     cin>>anotheragain;
     switch (anotheragain){
            case 1 : measuremenu(choice);
            break;
            case 2 : exit(1);
            break;
            default : "That doesn't work, try again";
            goto four;
     }
     }      
Last edited on
It's much easier to read your code if you use consistent indentation.

The use of goto also makes the code hard to follow.
well i believe ctrl+f helps find goto's but to me they're not hard to follow, the indentation to me is consistent, as far as my program goes, any help?
I don't see any problems when I run your programs.

You have a few like this in your code:
default : "That doesn't work, try again";
This doesn't do anything. You probably want to use cout here.
o yea forgot the cout lol woops, but um i need help putting it together as in one program, with a full menu that either calls time or measurements
I think you can just copy all the functions except the main functions. Make a new menu that asks if you want to convert times or measurements and call the correct menu function depending on the choice. It will be very similar to the other menu functions.
yea i tried that but for some reason it won't work
Topic archived. No new replies allowed.