init-declaration error?

I tried making a code to average 3 numbers but it keeps giving me init-declaration errors for line 3, please tell me what I've done wrong

#include<iostream>
int main()
using namespace;

{

double dnumber1 = 0.0;
double dnumber2 = 0.0;
double dnumber3 = 0.0;

cout << "please enter 3 numbers " << endl;
cin >> dnumber1;
cin >> dnumber2;
cin >> dnumber3;

daverage = (dnumber1 + dnumber2 + dnumber3) / 3;

cout << "the average of the numbers is: " << daverage << endl;

cin.ignore();
cin.ignore();
return 0;

}
using namespace;

This must be -

using namespace std;

The commands cout, cin, cin.ignore() etc..... are defined under std namespace.


daverage = (dnumber1 + dnumber2 + dnumber3) / 3;
You did not define daverage before using.

double daverage = (dnumber1 + dnumber2 + dnumber3) / 3;


EDIT : You need not declare dnumber1, dnumber2, dnumber3 as 0.0 . You can just use
double dnumber1, dnumber2, dnumber3;
Last edited on
#include<iostream>

using namespace std;
int main()


{

double dnumber1, dnumber2, dnumber3;

cout << "please enter 3 numbers " << endl;
cin >> dnumber1;
cin >> dnumber2;
cin >> dnumber3;

double daverage = (dnumber1 + dnumber2 + dnumber3) / 3;

cout << "the average of the numbers is: " << daverage << endl << endl;

cin.ignore();
cin.ignore();
return 0;

}
okay so i fixed it up and it compiled properly on my dev c++ put when i run it it comes up with an error message:
The NTVDM CPU has encountered an illegal instruction.
CS:1232 IP:0103 OP:63 6C 7564 65 Choose 'Close' to terminate
What should I do?
That's strange. It compiles and runs perfectly for me in Visual C++ 2008 express edition.
Tell me, do you have multiple MinGW's installed ?
I tried running it visual c++ 2008 and it says there is 1 error and says it fails? so I really don't know
It runs perfectly for me too.
After some *minimal* research (google) it looks like one possibility is that a 32 bit application is trying to run as a 16 bit one or vice versa.

There is some information here: http://www.techimo.com/forum/technical-support/117644-ntdvm-cpu-has-encountered-illegal-instruction.html#post1182475

Is your compiler setup trying to create this as a 16bit DOS application? It might be worth making sure it is being compiled as a 32bit executable.
I, for my part, happily left Windows years ago and I have never looked back.... 16bit mutter mutter DOS emulation mutter mutter...
how do you check? and if it is 16bit DOS how do I change it?
I have never used Windows for C++ so I have no idea.
What compiler generated that executable? If it's an old version of a Borland compiler (e.g. Turbo C++ 5.x), then it's very likely it's generating 16-bit code.

Galik: This forum has an "edit post" feature for a reason.
Topic archived. No new replies allowed.