It looks like you're new here. If you want to get involved, click one of these buttons!

- 140.8K All Categories
- 103.7K Programming Languages
- 6.5K Assembler Developer
- 1.9K Basic
- 40K C and C++
- 2.9K C#
- 7.9K Delphi and Kylix
- 4 Haskell
- 9.7K Java
- 4.1K Pascal
- 1.3K Perl
- 2K PHP
- 546 Python
- 37 Ruby
- 4.4K VB.NET
- 1.6K VBA
- 20.8K Visual Basic
- 2.6K Game programming
- 315 Console programming
- 91 DirectX Game dev
- 1 Minecraft
- 112 Newbie Game Programmers
- 2 Oculus Rift
- 9K Applications
- 1.8K Computer Graphics
- 741 Computer Hardware
- 3.4K Database & SQL
- 535 Electronics development
- 1.6K Matlab
- 628 Sound & Music
- 257 XML Development
- 3.3K Classifieds
- 199 Co-operative Projects
- 198 For sale
- 190 FreeLance Software City
- 1.9K Jobs Available
- 603 Jobs Wanted
- 209 Wanted
- 2.9K Microsoft .NET
- 1.8K ASP.NET
- 1.1K .NET General
- 3.4K Miscellaneous
- 8 Join the Team
- 354 Comments on this site
- 69 Computer Emulators
- 2.1K General programming
- 187 New programming languages
- 627 Off topic board
- 201 Mobile & Wireless
- 73 Android
- 126 Palm Pilot
- 338 Multimedia
- 154 Demo programming
- 184 MP3 programming
- Bash scripts
- 27 Cloud Computing
- 53 FreeBSD
- 1.7K LINUX programming
- 370 MS-DOS
- Shell scripting
- 321 Windows CE & Pocket PC
- 4.1K Windows programming
- 940 Software Development
- 417 Algorithms
- 68 Object Orientation
- 91 Project Management
- 95 Quality & Testing
- 268 Security
- 7.7K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 4 Bootstrap Themes
- 55 CGI Development
- 28 ColdFusion
- 224 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 37 JQuery
- 305 WEB Servers
- 150 WEB-Services / SOAP

Bananae
Member Posts: **1**

in Windows XP

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.

// 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

#include

#include

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

#include

#include

#include

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;

}

Thank you for all the help!

// 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

#include

#include

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

#include

#include

#include

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;

}

Thank you for all the help!

Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven

© 1997-2015 Programmersheaven.com - All rights reserved.