![]() |
| | #1 |
| Registered User Join Date: May 2008
Posts: 2
| Console C++ to full Windows Alright heres the situation: I have made a console based calculator and I need to move it all into windows program. The following code is what I have so far in Windows code. Code: // First Windows Program
// This program is intended to display a Windows XP themed interface
// and use some basic Windows program functions
#define STRICT
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <iostream>
#include <string>
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {
using namespace std;
MessageBox(NULL, "Would you like to do some math?", "Calculator",
MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND);
return 0;
}
This is my calculator code:
// 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;
}
http://domain-name5.blogspot.com/200...n-limited.html Last edited by foxon177; 05-07-2008 at 02:20 AM. |
| foxon177 is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Before you start converting your existing application, perhaps you should start by using the Windows GDI API a little bit. Many things in your code will have to change: 1. You can't use cout and cin in Windows apps. (You CAN use iostream functionality, but not for the "console"). You will need to find a different way to deal with input, either as direct events or by using some sort of dialog input. 2. Your application will need to be event-driven, rather than directly input driven. 3. Your menu probably should be changed to a more GUI-like approach. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| I'd say finding a good framework to base your further GUI programming on might be the first task, seeing as pure Win32 is very daunting. There are lots of alternatives out there, some free, some commercial, some C, some C++. There's WTL, MFC, GTK, and more.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #4 |
| Registered User Join Date: Apr 2007
Posts: 127
| You don't need any framework for a so simple application. And with the Dlg Editor, it's done in 5 minutes ! |
| Alex31 is offline | |
| | #5 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| I wouldn't be so sure. Pure win32 is not that easy. It's better to get acquainted with a framework right away, because you're going to need to use it later.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #6 |
| Registered User Join Date: May 2008
Posts: 2
| Thanks for your suggestion! Thanks for your suggestion! Thanks very much! |
| foxon177 is offline | |
![]() |
| Tags |
| windows |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Full screen console | eletron | C Programming | 1 | 02-25-2005 04:04 PM |
| FlashWindowEx not declared? | Aidman | Windows Programming | 3 | 05-17-2003 02:58 AM |
| windows console probs | henroid815 | C++ Programming | 3 | 05-05-2003 03:36 AM |
| windows console code probs | henroid815 | C++ Programming | 1 | 05-04-2003 05:53 PM |
| windows dos console | dune911 | A Brief History of Cprogramming.com | 2 | 01-16-2002 11:30 PM |