Problem with my calculator.

Write your question here.

Hello, I'm working on this code for an assignment and I keep getting the error C2447. I was hoping you all could help me understand this issue so I can go on. I'm working on a calculator.

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
  #include <iostream>
using namespace std;
void doMenu()
{
    system("cls");
int E;
int S;
int T;
int R;
int P;
int A;
int X;

    cout << "---------------" << endl;
    cout << " Menu Options: " << endl;
    cout << "---------------" << endl;
    cout << "  Ellipse   " << E << endl;
    cout << "  Sector     " << S << endl;
    cout << "  Triangle    " << T << endl;
    cout << "  Rhombus     " << R << endl;
    cout << "  Pentagram     " << P <<endl;
    cout << "  About   " << A << endl;
    cout << "  Exit    " << X << endl;
    cout << "---------------" << endl;
}
//
{
void do E()
double a, b, result;

	cout << "Enter the first number please." endl;
	cin << a;
	cout << "Enter the second number please." endl;
	cin << b;
	result = a * b;
	cout << "Area = " << result << endl;
system("pause");
}
What is the '{' on line 27 doing there?
I thought it was supposed to be there.

I've edited it, but still it does not work....
apologies, i didnt see his main() :)
Last edited on
I've made that change and now I have a lot of errors....
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
#include <iostream>
using namespace std;
void main()
{
    system("cls");
int E;
int S;
int T;
int R;
int P;
int A;
int X;

    cout << "---------------" << endl;
    cout << " Menu Options: " << endl;
    cout << "---------------" << endl;
    cout << "  Ellipse   " << E << endl;
    cout << "  Sector     " << S << endl;
    cout << "  Triangle    " << T << endl;
    cout << "  Rhombus     " << R << endl;
    cout << "  Pentagram     " << P <<endl;
    cout << "  About   " << A << endl;
    cout << "  Exit    " << X << endl;
    cout << "---------------" << endl;
}
//
void do E()
double a, b, result;

	cout << "Enter the first number please." endl;
	cin << a;
	cout << "Enter the second number please." endl;
	cin << b;
	result = a * b;
	cout << "Area = " << result << endl;
system("pause");
}


Errors below:

1>.\Calculator.cpp(27) : warning C4091: '' : ignored on left of 'void' when no variable is declared
1>.\Calculator.cpp(27) : error C2143: syntax error : missing ';' before 'do'
1>.\Calculator.cpp(27) : error C2059: syntax error : 'do'
1>.\Calculator.cpp(30) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(31) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(32) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(32) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(32) : error C2086: 'int cout' : redefinition
1> .\Calculator.cpp(30) : see declaration of 'cout'
1>.\Calculator.cpp(33) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(33) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(33) : error C2086: 'int cin' : redefinition
1> .\Calculator.cpp(31) : see declaration of 'cin'
1>.\Calculator.cpp(34) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(34) : error C2065: 'a' : undeclared identifier
1>.\Calculator.cpp(34) : error C2065: 'b' : undeclared identifier
1>.\Calculator.cpp(35) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(35) : error C2086: 'int cout' : redefinition
1> .\Calculator.cpp(30) : see declaration of 'cout'
1>.\Calculator.cpp(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(36) : error C2365: 'system' : redefinition; previous definition was 'function'
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdlib.h(521) : see declaration of 'system'
1>.\Calculator.cpp(36) : error C2440: 'initializing' : cannot convert from 'const char [6]' to 'int'
1> There is no context in which this conversion is possible
1>.\Calculator.cpp(37) : error C2059: syntax error : '}'
1>.\Calculator.cpp(37) : error C2143: syntax error : missing ';' before '}'
1>.\Calculator.cpp(37) : error C2059: syntax error : '}'
1>Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\Calculator\Calculator\Debug\BuildLog.htm"
1>Calculator - 24 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
void do E()

What is the "do" doing there?
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
#include <iostream>
using namespace std;
void main()
{
    system("cls");
int E;
int S;
int T;
int R;
int P;
int A;
int X;

    cout << "---------------" << endl;
    cout << " Menu Options: " << endl;
    cout << "---------------" << endl;
    cout << "  Ellipse   " << E << endl;
    cout << "  Sector     " << S << endl;
    cout << "  Triangle    " << T << endl;
    cout << "  Rhombus     " << R << endl;
    cout << "  Pentagram     " << P <<endl;
    cout << "  About   " << A << endl;
    cout << "  Exit    " << X << endl;
    cout << "---------------" << endl;
}
//
void E()
double a, b, result;

	cout << "Enter the first number please." endl;
	cin << a;
	cout << "Enter the second number please." endl;
	cin << b;
	result = a * b;
	cout << "Area = " << result << endl;
system("pause");
}


And my errors.

1>------ Build started: Project: Calculator, Configuration: Debug Win32 ------
1>Compiling...
1>Calculator.cpp
1>.\Calculator.cpp(28) : error C2144: syntax error : 'double' should be preceded by ';'
1>.\Calculator.cpp(30) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(30) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(31) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(32) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(32) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(32) : error C2086: 'int cout' : redefinition
1> .\Calculator.cpp(30) : see declaration of 'cout'
1>.\Calculator.cpp(33) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(33) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(33) : error C2086: 'int cin' : redefinition
1> .\Calculator.cpp(31) : see declaration of 'cin'
1>.\Calculator.cpp(34) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(34) : error C2371: 'result' : redefinition; different basic types
1> .\Calculator.cpp(28) : see declaration of 'result'
1>.\Calculator.cpp(34) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
1>.\Calculator.cpp(35) : error C2143: syntax error : missing ';' before '<<'
1>.\Calculator.cpp(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(35) : error C2086: 'int cout' : redefinition
1> .\Calculator.cpp(30) : see declaration of 'cout'
1>.\Calculator.cpp(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.\Calculator.cpp(36) : error C2365: 'system' : redefinition; previous definition was 'function'
1> C:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdlib.h(521) : see declaration of 'system'
1>.\Calculator.cpp(36) : error C2440: 'initializing' : cannot convert from 'const char [6]' to 'int'
1> There is no context in which this conversion is possible
1>.\Calculator.cpp(37) : error C2059: syntax error : '}'
1>.\Calculator.cpp(37) : error C2143: syntax error : missing ';' before '}'
1>.\Calculator.cpp(37) : error C2059: syntax error : '}'
1>Build log was saved at "file://c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\Calculator\Calculator\Debug\BuildLog.htm"
1>Calculator - 22 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I'm still trying to figure this out. I got more errors than I had with my first issue...

-____-
Last edited on
You need to go back to your textbook and learn the syntax for defining a function. You need to enclose your function definition inside curly braces. You've managed to do it right for your main function, so you clearly know how to do it.
Sadly, my class was never given a textbook. u_u But....GOOGLE!!!!
you also have unitialized variables in your main()

and cin's in your function should use >>'s and not <<'s.

uninitialized? How so?

I've changed the << to >> for the CIN, don't know how I confused those two....

so now I have....

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
#include <iostream>
using namespace std;
void main()
{
    system("cls");
int E;
int S;
int T;
int R;
int P;
int A;
int X;

    cout << "---------------" << endl;
    cout << " Menu Options: " << endl;
    cout << "---------------" << endl;
    cout << "  Ellipse   " << E << endl;
    cout << "  Sector     " << S << endl;
    cout << "  Triangle    " << T << endl;
    cout << "  Rhombus     " << R << endl;
    cout << "  Pentagram     " << P <<endl;
    cout << "  About   " << A << endl;
    cout << "  Exit    " << X << endl;
    cout << "---------------" << endl;
}
//
void E()
double a, b, result;

	cout << "Enter the first number please." endl;
	cin >> a;
	cout << "Enter the second number please." endl;
	cin >> b;
	result = a * b;
	cout << "Area = " << result << endl;
system("pause");
}
Last edited on
i think you need to listen to mikey and go back to the textbook(s).

http://www.cplusplus.com/doc/tutorial/functions/

Last edited on
Sadly, my class was never given a textbook. u_u But....GOOGLE!!!!

Well, whatever source you're using to learn how to define a function - you need to go back to it, and learn properly the syntax.

Defining and calling functions is such a basic and fundamental part of C/C++ programming that you really need to learn how to do it.
Topic archived. No new replies allowed.