Hi
The computer I'm using has Win Visa installed. I'm using Code::Blocks and run compiled from within the Code::Blocks.
CODE 1 compiles and runs fine. CODE 2 compiles but when I try to run it the command prompt (DOS window) crashes without even running the compiled code. I have even tried Dev-C++ the same problem is encountered. At the bottom you can find the problem details shown by the crashed DOS window and also a linked screenshot of crashed window. Please help me to solve this issue.
CODE 1
Code:
// calculating area of a circle using user-defined function
#include <iostream>
#include <cstdlib>
using namespace std;
float area(float dummy);
int main()
{
float r; float a;
cout << "enter radius: "; cin >> r;
a = area(r);
cout << a << endl;
system("pause");
return 0;
}
//------------------------------------
// area(int), function definition
float area(float dummy)
{
float Area;
Area = 3.1416*(dummy*dummy);
return Area;
}
//--------------------------------------
CODE 2
Code:
// average_weight.cpp
// read 10 or n weights and then find average
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int n;
float w[n];
float total_weight=0;
cout << "how many weights: "; cin >> n;
for (int i=0; i<n; i++)
{
cout << "enter weight #" << (i+1) << ": "; cin >> w[i];
}
cout << endl;
for (int i=0; i<n; i++)
{
cout << "entered weight #" << (i+1) << " is: " << w[i] << endl;
}
cout << endl;
for (int i=0; i<n; i++)
{
total_weight += w[i];
}
float average_weight = total_weight/n;
cout << "average weight is: " << average_weight << endl;
system("pause");
return 0;
}
Problem details given by the crashed window:
Code:
Problem signature:
Problem Event Name: APPCRASH
Application Name: average_weight.exe
Application Version: 0.0.0.0
Application Timestamp: 4de7ebf8
Fault Module Name: average_weight.exe
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 4de7ebf8
Exception Code: c00000fd
Exception Offset: 000140ce
OS Version: 6.0.6001.2.1.0.768.11
Locale ID: 1033
Additional Information 1: 6199
Additional Information 2: bcfd5cce14b739ebe66a3b520492755c
Additional Information 3: 973d
Additional Information 4: a6b61f04fc8b13590bb3150313d0cc3d
Read our privacy statement:
http://go.microsoft.com/fwlink/?linkid=50163&clcid=0x0409
Link:
http://img855.imageshack.us/img855/4...shedwindow.jpg