Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Quboid

macrumors 6502
Original poster
Oct 16, 2006
441
0
everywhere
I used windows ansi C compilers for a while since excode didn't have some of the functions that my teachers at school use. But now that we are doing C++ i decided to move to xcode.

Now the second program i wrote (one involving structures). Has an error that i donot recognise. Can anybody help me with this?

Error:
expected initializer before "alumno"
'alumno' was not declared in this scope


SOURCE CODE:

#include<iostream.h>

struct datos{
int ide, edad;
char nombre[30];
float promedio;
}
datos alumno={0,0,"",0.0};

//funciones

void entrar();
void mostrar();

int main(){
entrar();
mostrar();
return 0;
}

void entrar(){
cout<<"ide";
cin>> alumno.ide;
cout<< "nombre";
cin>>alumno.nombre;
}
void mostrar(){
cout<<alumno.ide<<"\n";
cout<<alumno.nombre;
}



thanks!
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Also don't you need a "using namespace std;" or "std::" prefix on your couts?
 

kpua

macrumors 6502
Jul 25, 2006
294
0
It's been a while since I've used C++, but this is how it has to be done in C:

Regarding this part of the code:

Code:
struct datos{
    int ide, edad;
    char nombre[30];
    float promedio;
};
datos alumno={0,0,"",0.0};

In C, you'd either have to typedef the struct like this:

Code:
typedef struct _datos{
    int ide, edad;
    char nombre[30];
    float promedio;
} datos;

or prepend 'struct' in the delcaration of the instance of the struct like this:

Code:
struct datos alumno={0,0,"",0.0};

Give that a try...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.