Re: [Dev-C++] Const member in a Struct
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2007-07-28 20:20:43
|
Please, use ASCII mail when posting to this list. Not all people are using
a web-baseed email reader...
You seem to be using a very funny indentation. Please don't.
To access an element of an array, you should write
array[0].member =3D 10;
You can not write lines like 1.name =3D "hydrogen".
Observe also that in C/C++, an array starts with index 0, and not index 1.
/pwm
On Sat, 28 Jul 2007, J Hall wrote:
>
> Here is a program that I have been working on.when I compile, i get an in=
valid suffix on floating const error on all the elements of the members of =
struct elements.Is this the type of situation that a pointer would help?It =
seems that since the periodic table has numbers 1-112, I ought to be able t=
o write a loop that gives the struct elements the members 1-112 ,any ideas?=
using namespace std;int i,e;char x[3];main(){for (i=3D1;i < 5;++i) { =
struct elements{ string name; int atomic_no; float atomi=
c_weight; }i; } 1.name =3D "hydrogen"; 1.atomic_no =
=3D 1; 1.atomic_weight =3D 1.007794; 2.name =3D "helium"; =
2.atomic_no =3D 2; 2.atomic_weight =3D 4; 3.name =3D "lithium"; =
3.atomic_no =3D 3; 3.atomic_weight =3D 6.941; 4.name =3D "bery=
lium"; 4.atomic_no =3D 4; 4.atomic_weight =3D 9.012182; 5.nam=
e =3D"boron"; 5.atomic_no =3D 5; 5.atomic_weight =3D 10.81=
1; string element; string title("\n\t You have selected :\t"); string =
no("\n\t The atomic number for "); string is(" is:\t"); string wgt("\n\t Th=
e atomic weight is:\t");printf ("\t The Begining of the Periodic Table of t=
he Elements \n");printf ("\t In the hopes of learning C programming and ele=
mental values. \n\n\n"); do {cout << "\n\t Please enter an Element you woul=
d like to examine : " ;cin >> element;if (element =3D=3D 1.name) { =
cout << title << 1.name; cout << no << 1.name << is << 1.ato=
mic_no; cout << wgt << 1.atomic_weight; } else if (el=
ement =3D=3D 2.name) { cout << title << 2.name; cout=
<< no << 2.name << is << 2.atomic_no; cout << wgt << 2.atomic_w=
eight; } else if (element =3D=3D 3.name) { cout << t=
itle << 3.name; cout << no << 3.name << is << 3.atomic_no; =
cout << wgt << 3.atomic_weight;} else if (element =3D=3D 3=
=2Ename) { cout << title << 3.name; cout << no << 3.=
name << is << 3.atomic_no; cout << wgt << 3.atomic_weight;} =
else if (element =3D=3D 4.name) { cout << title << 4.nam=
e; cout << no << 4.name << is << 4.atomic_no; cout <<=
wgt << 4.atomic_weight;} else if (element =3D=3D 5.name) { =
cout << title << 5.name; cout << no << 5.name << is << 5=
=2Eatomic_no; cout << wgt << 5.atomic_weight;} cout <=
< "\n\n\t Again Yes/No :"; cin >> x;}while (!strcmp(x,"yes")) ;}
> _________________________________________________________________
> See what you=92re getting into=85before you go there.
> http://newlivehotmail.com
|