#include "stdafx.h"
#include "iostream.h"
#include "string.h"
#include "stdlib.h"
#include "windows.h"
#include "time.h"
struct stud
{char surname[25];
int exam[5];
float stredb;
};
void main()
{stud i31[20];
for(int n = 0; n < 20; n++)
{cout<<"Vvedite familiy: \n";
cin>>i31.surname;
for(int m = 0; m < 5; m++)
i31[n].exam[m];
}
for(int m = 0; m < 5; m++)
{ buft = i31[n].exam[m];
i31[n].sredb = buft;
cout<<"\n familia: "<<"Stred bal: "<<i31[n].sredb;
cout<<endl;
}
}
Работа со Структурами
Код:
Код ошибки:
Код:
--------------------Configuration: struct - Win32 Debug--------------------
Compiling...
struct.cpp
E:\C++ my project\structuri\struct\struct.cpp(21) : error C2228: left of '.surname' must have class/struct/union type
E:\C++ my project\structuri\struct\struct.cpp(27) : error C2065: 'buft' : undeclared identifier
E:\C++ my project\structuri\struct\struct.cpp(28) : error C2039: 'sredb' : is not a member of 'stud'
E:\C++ my project\structuri\struct\struct.cpp(12) : see declaration of 'stud'
E:\C++ my project\structuri\struct\struct.cpp(29) : error C2039: 'sredb' : is not a member of 'stud'
E:\C++ my project\structuri\struct\struct.cpp(12) : see declaration of 'stud'
Error executing cl.exe.
struct.exe - 4 error(s), 0 warning(s)
Compiling...
struct.cpp
E:\C++ my project\structuri\struct\struct.cpp(21) : error C2228: left of '.surname' must have class/struct/union type
E:\C++ my project\structuri\struct\struct.cpp(27) : error C2065: 'buft' : undeclared identifier
E:\C++ my project\structuri\struct\struct.cpp(28) : error C2039: 'sredb' : is not a member of 'stud'
E:\C++ my project\structuri\struct\struct.cpp(12) : see declaration of 'stud'
E:\C++ my project\structuri\struct\struct.cpp(29) : error C2039: 'sredb' : is not a member of 'stud'
E:\C++ my project\structuri\struct\struct.cpp(12) : see declaration of 'stud'
Error executing cl.exe.
struct.exe - 4 error(s), 0 warning(s)
[QUOTE=X-enot]
Код:
cin>>i31.surname;
[/QUOTE]
Код:
cin >> i31[n].surname;
2.
[QUOTE=X-enot]
Код:
buft = i31[n].exam[m];
[/QUOTE]
Код:
int buft = i31[n].exam[m];
3.
stredb вместо sredb.
Читайте код внимательнее. :)
Код:
#include "stdafx.h"
#include "iostream.h"
#include "string.h"
#include "stdlib.h"
#include "windows.h"
#include "time.h"
struct stud
{char surname[25];
int exam[5];
float stredb;
};
void main()
{stud i31[20];
for(int n = 0; n < 20; n++)
{cout<<"Vvedite familiy: \n";
cin >> i31[n].surname;
for(int m = 0; m < 5; m++)
i31[n].exam[m];
}
for(int m = 0; m < 5; m++)
{ int buft = i31[n].exam[m];
i31[n].stredb = buft/2;
cout<<"\n familia: "<<"Stred bal: "<<i31[n].stredb;
cout<<endl;
}
}
#include "iostream.h"
#include "string.h"
#include "stdlib.h"
#include "windows.h"
#include "time.h"
struct stud
{char surname[25];
int exam[5];
float stredb;
};
void main()
{stud i31[20];
for(int n = 0; n < 20; n++)
{cout<<"Vvedite familiy: \n";
cin >> i31[n].surname;
for(int m = 0; m < 5; m++)
i31[n].exam[m];
}
for(int m = 0; m < 5; m++)
{ int buft = i31[n].exam[m];
i31[n].stredb = buft/2;
cout<<"\n familia: "<<"Stred bal: "<<i31[n].stredb;
cout<<endl;
}
}
Код:
--------------------Configuration: struct - Win32 Debug--------------------
Compiling...
struct.cpp
E:\C++ my project\structuri\struct\struct.cpp(28) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
Linking...
struct.exe - 0 error(s), 1 warning(s)
Compiling...
struct.cpp
E:\C++ my project\structuri\struct\struct.cpp(28) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
Linking...
struct.exe - 0 error(s), 1 warning(s)
Код:
i31[n].stredb = buft/2;
если напишешь так, то предупреждение вылетать не должно
Код:
i31[n].stredb =(float)buft/2;