just need some thoughts

ok. i have to make a until converter by using only switch cases. i have to let the user choose EXACLTY from what unit to which. I think its stupid but thats the rules. just wanted to see how i was doing. WARINIG!!! its not even close to done yet so...yah
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
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace;

int main(){
    system("CLS")
    char loop
    float in
    float ft
    float yd
    float ml
    float cm
    float km
    float m
    float mm
    char systemfrom
    char systemto
    char from
    char to

  do 
  {
         cout << "Welcome to Measurment System Converter" << endl; 
         cout <<"Enter What system you want to convert from" << endl; 
         cout << "Convert from U.S.[u] or Metric[m]: ";
         cin >> systemfrom
         
         switch(systemfrom) {
                   case 'u':
                        cout << "Choose Starting measurement type by typing in it 1 or 2-" << endl;
                        cout << "lowercase abrevaitions are the flowing" << endl;
                        cout << "inches=a  feet=b  yard=c   miles=d" << endl;
                        cout << "Choose here: ";
                        cin >> from;
                            switch(from){
                                        case 'a':
                                             cout << "You have choosen to convert from inches" << endl;
                                             cout << "What system would you like to convert to? [m/u]: ";
                                             cin >> systemto;
                                                 switch(systemto){
                                                                  case 'm':
                                                                       cout << endl; <<"You have chosen to convert to metric" << endl;
                                                                       cout << "Which unit would you like to convert to?" << endl;
                                                                       cout << "millimeters=a  centimeters=b  meters=c"<< endl;
                                                                       cout << "kilometers=d     Choose here: ";
                                                                       cin >> to;
                                                                           switch(to){
                                                                                     case 'a':
                                                                                          cout << "You have chosen inches to millimeters" << endl
                                                                                          cout << "Input a inches amout: "
                                                                                          cin >> in;
                                                                                          mm = in * 25.4;
                                                                                          cout << endl; << endl;
                                                                                          cout << "The Answer is " << mm << endl;                                                                                         
                                                                                     break;
                                                                                     
                                                                                     case 'b':
                                                                                          cout << "You have chosen inches to centimeters" << endl
                                                                                          cout << "Input a inches amout: "
                                                                                          cin >> in;
                                                                                          cm = in * 2.54;
                                                                                          cout << endl; << endl;
                                                                                          cout << "The Answer is " << cm << endl;
                                                                                          
                                                                                     break;
                                                                                     
                                                                                     case 'c':
                                                                                          
                                                                                     break;
                                                                                     
                                                                                     case 'd':
                                                                                          
                                                                                     break;
                                                                                     
                                                                                     default:
                                                                                             
                                                                                     break;
                                                                                      
                                                                  break;
                                                                  
                                                                  case 'u':
                                                                       
                                                                  break;
                                                                  
                                                                  default:
                                                                          
                                                                  break;
                                        
                                        break;     
                                        
                                        case 'b':
                                             
                                        break;
                                        
                                        case 'c':
                                             
                                        break;
                                        
                                        case 'd':
                                             
                                        default:
                                                
                                        default
                                        
                        
                   case 'm':
                        
                   default :                                                     
    
    
because the bulk of the message and all is the same for each choice, you may want to use a variable.

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
/* libraries go here */

#define MM   1.0
#define CM   10.0
#define INCH 254.0
#define FOOT 12*INCH
/* etc. */

#define CHOSE_MM 1
/* etc. */

{
  ..
  printf("what will you convert from?...");
  cin >> input;
  switch(input){
    case CHOSE_MM:
      convert_from = MM;
      break;
    ...
  }
  printf("what will you convert to?...");
  ...
  result = convert_from / convert_to * value;
  ...
}


Hope it helps reasonably
Last edited on
it does but im not aloud to do that i asked. i was thinking of a way using classes
closed account (z05DSL3A)
How about one switch for the input convertion (convert to somthing like mm) then have a switch to convert the 'internal' value to the required output?
hmm that is a thoguht. Why do i really need someone to chose a system. Even though this 'assignment"(really im teaching myself but i follow guidelines of a family member who does no it, but ya. Thanks Grey Wolf. i read other answer u did ur amAAAAAAZING!!!!!!!!!!!
Topic archived. No new replies allowed.