Conversion Master 3000x

I've literally just started learning C++ so i thought i share my first real-ish program to get some feedback, please feel free to comment on the program as any constructive critique you can give me wil help in the future.

link - http://www.megaupload.com/?d=X7AAFOH6

source code:-
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
//////////////////////////////////////////////
/// Conversion Master ////// Created by /////
/////// 3000x V5 ////////// Aaron Walwyn ///
///////////////////////////////////////////


#include <iostream>

using namespace std;



float conversionData() // Data entered by the user
{
    float num;
    cout << " Please enter figure: ";
    cin >> num;
    return num;
}

int displayMenu() // The Main menu displayed at the start of program
{
    int value;
    cout << "\n Welcome to the Conversion Master 3000x.\n Please choose a conversion option.\n\n";
            cout << " Temperature\n\n"
                 << "    1) Fahrenheit to Celsius\n"
                 << "    2) Celsius to Fahrenheit\n"
                 << "----------------------------\n\n"
                 << " Length\n\n"
                 << "    3) Metres to Feet\n"
                 << "    4) Feet to Metres\n"
                 << "    5) Kilometres to Miles\n"
                 << "    6) Miles to Kilometres\n"
                 << "----------------------------\n\n"
                 << " 7) Exit\n\n"
                 << " Choice: ";
            cin >> value;
            return value;
}


int main(int argc, char *argv[])
{
    int menu, repeat;
    float num, ans;
    
    repeat= 1; // This keeps the loop going infinatly unless exited
    
while (repeat=1) // Loop
    {
        system("CLS");
        menu = displayMenu();
        system("CLS");
        
        if (menu<7)
            {
                num = conversionData();
                system("CLS");
            }
    
                switch (menu)
                     {   
                        case 1:
                            ans = (num-32*5/9);
                            break;
                        case 2:
                            ans = (num*5/9+32);
                            break;
                        case 3:
                            ans = (num*3.28084);
                            break;
                        case 4:
                            ans = (num/3.28084);
                            break;
                        case 5:
                            ans = (num/1.6);
                            break;
                        case 6:
                            ans = (num*1.6);
                            break;
                         default: // Exit procedure
                            cout << "\n Thank you for using the Conversion Master 3000x, Please come again soon.\n\n ";
                            system("PAUSE");
                            return EXIT_SUCCESS;
                        }
    
        // The display giveing the answer
        cout << "\n The figure given was: " << num << "\n\n";
        cout << "\n The answer is: " << "| " << ans << "|" << "\n\n";
        cout << " Thank you for using the Conversion Master 3000x.\n Please continue to return to home screen.\n\n ";
        system("PAUSE");
        //loop now repeats because repeat still equals true
    }
      
}



Thanks.
Last edited on
You really expect us to donwload and run an exe file?... If you want us to take a look at your program give us a link to the source code instead, or post it here if it's not too big.
Last edited on
ok thnx i'll post it again in as second.
OK Ive posted the source code above.
It's not bad. I have a few minor quips with it, however.

Specifically,
1. system("PAUSE") -- please don't use system(): http://cplusplus.com/forum/articles/11153/
2. system("CLS") -- see above, and also see: http://cplusplus.com/forum/articles/10515/
3. Your indentation is a little inconsistent.
4. using namespace std; -- I know a lot of tutorials (including the one here, sadly) give the impression that it's good, I strongly recommend you don't use it. Some people here will agree with me and others won't; but personally I don't think it should ever be used. By all means, use using; but reserve it for separate symbols, as in using std::cout. Personally I don't think that the using directive should ever be used, but the C++ committee in its infinite wisdom decided to include it.

That's all really. The first problem is easy to fix. Instead of system("PAUSE") we can use the C++ iostream library.
This:
std::cin.get();
will make the program block until the ENTER key is pressed:
1
2
std::cout << "Press ENTER to continue...\n";
std::cin.get();

or better yet,
1
2
std::cout << "Press ENTER to continue...\n";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

(Note: You will need to include <limits> to use the last one).

As for the system("CLS"); Duoas provides examples for that.
You might want to take a second look at the output of 5/9 and 5/9.0.
Topic archived. No new replies allowed.