Putting a console program into Windows program

I made a C++ console program (it's a calculator) and I was wondering how I could put this into the Windows Template(http://tinyurl.com/63ydtc) to make it cleaner looking and a true Windows program. Example of how I want it to look: http://tinyurl.com/623drd
Except I want my program in that window ;).
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
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
// Calculator

// Include files below

#include <iostream>
#include <string>
#include <math.h>
#include <cstdlib>
using namespace std;

//Beginning of calulator

int main()
{
      //Mathematical operators' corresponding number
      //Done = 5;
      //Subtraction = 4;
      //Addition = 3;
      //Multiplication = 2;
      //Division = 1;
      
     int answer;
     
     //Answer must be initialized to be used
     
     cout << "What basic mathematical operator shall I perform ?" << endl;
     cout << "Please answer with: Division(1), Multiplication(2), Addition(3), Subtraction(4)" << endl;
     cout << "Square Root(5), Sine(6), Cosine(7), Tangent(8), Exponetial(9) or End Program(10)" << endl;
     cout << "Want a operator not seen here? More operators can be added at your request!" << endl;
     cin >> answer;
     
     while(answer!=10) // This begins a loop that will only end when answer is equal to 10
     {
     
     if (answer == 1) //Division section of the calculator
     {                              
                // Long double is the type of variable that can have up to 15 digits
                // Again variables must be initialized before using them.
                // However because of the braces around this section the variables
                // are local and can be initialized/used in other sections again
                
                long double value1;
                long double value2;             
                
                // This asks for values and then inputs the values into the variables
                
                      cout << "Input value to be divided: ";
                      cin >> value1;
                      cout << "Input the dividend: ";
                      cin >> value2;
                
                //Dividing the values and storing the answer to value1
                
                value1 /= value2;
                cout << "Answer: "<< value1 << endl <<endl;
                cout << "Please input the next operation number you would like to preform." << endl;
                cin >> answer;
                
     }
     
     if (answer == 2) //Multiplication section of the calculator
     { 
                
                long double value1;
                long double value2;              
                 
                      cout << "Input first number: ";
                      cin >> value1;
                      cout << "Input the second number: ";
                      cin >> value2;
                
                value1*=value2;
                cout << "Answer: "<< value1 << endl <<endl;
                cout << "Please input the next operation number you would like to preform." << endl;
                cin >> answer;
     }
     if (answer == 3) //Addition section of the calculator
     { 
                
                long double value1;
                long double value2;
                 
                      cout << "Input the first number : ";
                      cin >> value1;
                      cout << "Input the second number: ";
                      cin >> value2;
                
                value1+=value2;
                cout << "Answer: "<< value1 << endl <<endl;
                cout << "Please input the next operation number you would like to preform." << endl;
                cin >> answer;
     }
     if (answer == 4) //Subtraction section of the calculator
     { 
                
                long double value1;
                long double value2;
                 
                      cout << "Input value to be subtracted from: ";
                      cin >> value1;
                      cout << "Input the number to subtract from the first: ";
                      cin >> value2;
                
                value1-=value2;
                cout << "Answer: "<< value1 << endl <<endl;
                cout << "Please input the next operation number you would like to preform." << endl;
                cin >> answer;
      }
     if (answer == 5) //root section of the calculator
     { 
                
                long double value1;
                long double value2;
                 
                      cout << "Input value to be square rooted: ";
                      cin >> value1;
                
                value2 = sqrt (value1);
                cout << "Answer: "<< value2 << endl <<endl;
                cout << "Please input the next operation number you would like to preform." << endl;
                cin >> answer;
      }
      if (answer == 6) //sine section of the calculator
      { 
                
                long double value1;
                long double value2;
                 
                      cout << "Input value to get the sine for: ";
                      cin >> value1;
                
                value2 = sin (value1);
                cout << "Answer: "<< value2 << endl <<endl;
                cout << "Please input the next operation number you would like to preform." << endl;
                cin >> answer;
       }
       if (answer == 7) //cosine section of the calculator
       { 
                
                long double value1;
                long double value2;
                 
                      cout << "Input value to get the cosine for: ";
                      cin >> value1;
                
                value2 = cos (value1);
                cout << "Answer: "<< value2 << endl <<endl;
                cout << "Please input the next operation number you would like to preform." << endl;
                cin >> answer;
       }
       if (answer == 8) //tangent section of the calculator
       { 
                
                long double value1;
                long double value2;
                 
                      cout << "Input value to get the tangent for: ";
                      cin >> value1;
                
                value2 = tan (value1);
                cout << "Answer: " << value2 << endl <<endl;
                cout << "Please input the next operation number you would like to preform." << endl;
                cin >> answer;
       }
       if (answer == 9) //exponetial section of the calculator
       { 
                
                long double value1;
                long double value2;
                 
                      cout << "Input value to raise exponentially: ";
                      cin >> value1;
                      cout << "Input exponet: ";
                      cin >> value2;
                      
                cout << "Answer: "<< pow (value1,value2)<< endl <<endl;
                cout << "Please input the next operation number you would like to preform." << endl;
                cin >> answer;
       }
       else
       {
       cout << "Please input a correct number" << endl;
       cin >> answer;
       }
      // Braces are needed at each level of abstraction
      }
      // Return value shows that program executed as expected and then ends the program
     return 0;
}
I dont know windows programming but a way to improve this would be to give the user and unlimited amount of numbers they could multiply, add, subtract, ect. Instead of value1 * value2 have:
answer *= value1;

replace the * sign with whatever operator you need. You would have to modify the code some so it asks the user if it wants to input another value but thats not hard.
thanks for the advice but come on could this really be that hard? I've figured out how to put text in the box but I need to have the entire program in the box. This would really help me as this is a project. Thanks. Heres a pic of it in execution:
<a href="http://img56.imageshack.us/my.php?image=windowsprogramexecutionud5.png"
Last edited on
Look up information on msdn.com about the Windows API...specifically the painting/button sections.
closed account (z05DSL3A)
@bananae
WTL is not necessarily that hard...if you understand Windows API programming. You can, as firedraco suggest, go to msdn and try to pick up odds and ends as you struggle forward but I would suggest buying a book - “Programming Windows (5th ed.)” by Charles Petzold.

If you want to have more of a look at WTL then you could start here:
http://www.codeproject.com/KB/wtl/


Last edited on
@bananae

Create a dialog based appliction using MFC in VS, and put a edit box on dialog,
then
1)instead of cout, use this->Edit1->Addstring("data")
2) put thereanother edit box to get input data

then you are there;)
What are MFC and VS?
closed account (z05DSL3A)
VS = Visual Studio, Microsoft's Integrated Development Environment (IDE).

MFC = Microsoft Foundation Class Library, a library that wraps portions of the Windows API in C++ classes
Alas, bananae, if you have to ask, you are way over your head.

As Grey Wolf indicated, neither Win32 API nor WTL are particularly difficult, but it is an entirely new programming paradigm for you, and takes a fair amount of study and effort to get the hang of it.

I would recommend getting C++Builder Explorer 2006, since that gives you a very nice IDE and a powerful and easy to use visual component library. Drag and drop stuff on your forms, set some properties, double click the events you want to handle (like button presses) and you'll be automatically placed in a spot where you can add your code. And it is 100% free.
http://cc.codegear.com/free/cppbuilder

No matter what you do, you've got a bit of a learning curve ahead of you. I also endorse Grey Wolf's recommendation to get yourself a textbook.

Another alternative would be to check out Tcl/Tk or Expect. (But that's yet another language. Alas.)
I got the builder :)
Last edited on
Topic archived. No new replies allowed.