### Calculator problems...

I tried to complie this in both VS c++ 2010 and bloodshed dev-c++ and it doesn't work in eather of them... Can someone please help me? I'm a complete beginner in c++ and i'm still learnign. It is at the message box I get the error.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980`` ``````#include "stdafx.h" #include #include #define UNICODE #include using namespace std; int main(){ string resp = "y"; do{ long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p; cout << "1)Add" << endl; cout << "2)Subtract" << endl; cout << "3)Multiply" << endl; cout << "4)Divide" << endl << endl;; cin >> a; if (a == 1) { cout << "\nEnter a number to add.\n"; cin >> b; cout << "Enter a second number to add.\n"; cin >> c; d = b+c; cout << endl << d << endl; } if (a == 2) { cout << "Enter a number to subtract.\n"; cin >> e; cout << "Enter a second number to subtract.\n"; cin >> f; g = e-f; cout << endl << g << endl; } if (a == 3) { cout << "Enter a number to multiply.\n"; cin >> h; cout << "Enter a second number to multiply.\n"; cin >> i; j = h*i; cout << endl << j << endl; } if (a == 4) { cout << "Enter a number to divide.\n"; cin >> k; cout << "Enter a second number to divide.\n"; cin >> l; m = k/l; if (k < l) { MessageBoxA(NULL, L"You can't divide like that!", L"Error"); } else { cout << endl << m << endl; } } cout << "Anything more to calculate? (y/n)" << endl; cin >> resp; } while (resp == "y"); do{ return 0; } while (resp == "n"); }``````

In bloodshed I get this error message:
` cannot convert `const wchar_t*' to `const CHAR*' for argument `2' to `int MessageBoxA(HWND__*, const CHAR*, const CHAR*, UINT)' `

And in VS I get shitloads of rows that i'm too lazy to read ;)

ALL HELP IS APPRECIATED!!
Last edited on
Well, this isn't a Windows program it's a terminal program, so you can't use MessageBox, so take that out. Then lines 74 to 79 are all wrong, you have two while loops that don't have any body, and a do loop that just returns back to the OS.
But is there anyway I can make some Message Box / Error msg?
If it's a terminal program, just output the error message to standard out:

`std::cout << "ERROR: Something has gone horribly wrong." << std::endl;`
Just use FatalAppExit() :)
 MikeyBoy: If it's a terminal program, just output the error message to standard out: std::cout << "ERROR: Something has gone horribly wrong." << std::endl;

i would use std::cerr istead of std::cout, since you can filter that with a shell for example
Last edited on
 i would use std::cerr istead of std::cout, since you can filter that with a shell for example

Good point - thanks!
Thanks everyone!

For std::cerr and std::cout it's just that the terminal window crashes before the message shows up!
Last edited on
Topic archived. No new replies allowed.