Windows run error

Hi
My codes are running.But i take Windows error.
My codes:
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
#include <iostream>
#include <cstring>
#include <math.h>
#include <stdlib.h>
#include <conio.h>
#define PI 3.14
using namespace std;


int main(){start:
char *figure,*property;
float area,field,volume;

float a,b,r;
cout<<"Would u want to make?";
cin>>property;
if((!strcmp(property,"area"))&&(!strcmp(property,"field"))&&(!strcmp(property,"volume"))){
cout<<"This property is undefinied.Press Y for to exit or Press N for to continue:";
if(kbhit()=='y')
goto start;
if(kbhit()=='n')
exit(1);

}else{
if((!strcmp(figure,"square"))&&(!strcmp(figure,"cube"))&&(!strcmp(figure,"circuit"))){
cout<<"This figure is undefinied.Press Y for to exit or Press N for to continue:";
if(kbhit()=='y')
goto start;
if(kbhit()=='n')
exit(1);
}
if((strcmp(figure,"square"))&&(strcmp(figure,"area"))){
cout<<"Enter your square's an edge:";
cin>>a;
area=4*a;
cout<<"If ur square's an edge length: "<<a<<" this square's area"<<area;
}

if((strcmp(figure,"square"))&&(strcmp(figure,"field"))){
cout<<"Enter your square's an edge:";
cin>>a;
field=a*a;
cout<<"If ur square's an edge length: "<<a<<" this square's field"<<field;
}

if((strcmp(figure,"cube"))&&(strcmp(figure,"volume"))){
cout<<"Enter your cube's an edge:";
cin>>a;
field=pow(a,3);
cout<<"If ur cube's an edge length: "<<a<<" this cube's volume"<<volume;
}

if((strcmp(figure,"circuit"))&&(strcmp(figure,"area"))){
cout<<"Enter your circuit's radius:";
cin>>r;
area=2*PI*r;
cout<<"If ur circuit's radius: "<<r<<" this circuit's area"<<area;
}

if((strcmp(figure,"circuit"))&&(strcmp(figure,"field"))){
cout<<"Enter your circuit's radius:";
cin>>r;
field=r*PI*r;
cout<<"If ur circuit's radius: "<<r<<" this circuit's field"<<field;
}
}
return 0;
}

Thanks for all helps now.
you said the error that is the variable 'property' used without being initialized?
what happend when i used vc9 run your code...
You're using strings incorrectly. The result is you are overwriting parts of memory in an non-deterministic way. That really bad.

You can fix this by using string (rather than char*) for strings. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <iostream>

using namespace std;

int main()
{
    string name;
    cout << "What is your name?: ";
    cin >> name;
    cout << endl;

    // demonstrate comparison
    if (name == "Helegurbann")
        cout << "Hello Creator!" << endl;
    else
        cout << "Hello " << name << endl;
    return 0;
}
Last edited on
Thnx
Topic archived. No new replies allowed.