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.

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
#include "stdafx.h"
#include <iostream>
#include <string.h>
#define UNICODE 
#include <windows.h>

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.