Jun 1, 2010 at 9:34am UTC
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;
}
Jun 1, 2010 at 9:46am UTC
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 Jun 1, 2010 at 9:50am UTC
Jun 1, 2010 at 10:05am UTC
#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?
Jun 1, 2010 at 10:24am UTC
That's strange. It compiles and runs perfectly for me in Visual C++ 2008 express edition.
Jun 1, 2010 at 10:31am UTC
Tell me, do you have multiple MinGW's installed ?
Jun 1, 2010 at 10:42am UTC
I tried running it visual c++ 2008 and it says there is 1 error and says it fails? so I really don't know
Jun 1, 2010 at 10:50am UTC
It runs perfectly for me too.
Jun 1, 2010 at 10:59am UTC
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.
Jun 1, 2010 at 11:01am UTC
I, for my part, happily left Windows years ago and I have never looked back.... 16bit mutter mutter DOS emulation mutter mutter...
Jun 1, 2010 at 11:04am UTC
how do you check? and if it is 16bit DOS how do I change it?
Jun 1, 2010 at 12:37pm UTC
I have never used Windows for C++ so I have no idea.
Jun 1, 2010 at 12:50pm UTC
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.