Re: [Dev-C++] Const member in a Struct
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: J H. <jsh...@ho...> - 2007-07-28 17:37:38
|
Here is a program that I have been working on.when I compile, i get an inva=
lid suffix on floating const error on all the elements of the members of st=
ruct elements.Is this the type of situation that a pointer would help?It se=
ems that since the periodic table has numbers 1-112, I ought to be able to =
write a loop that gives the struct elements the members 1-112 ,any ideas?us=
ing namespace std;int i,e;char x[3];main(){for (i=3D1;i < 5;++i) { s=
truct elements{ string name; int atomic_no; float atomic_=
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 "beryliu=
m"; 4.atomic_no =3D 4; 4.atomic_weight =3D 9.012182; 5.name =
=3D"boron"; 5.atomic_no =3D 5; 5.atomic_weight =3D 10.811;=
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 The =
atomic weight is:\t");printf ("\t The Begining of the Periodic Table of the=
Elements \n");printf ("\t In the hopes of learning C programming and eleme=
ntal values. \n\n\n"); do {cout << "\n\t Please enter an Element you would =
like to examine : " ;cin >> element;if (element =3D=3D 1.name) { =
cout << title << 1.name; cout << no << 1.name << is << 1.atomi=
c_no; cout << wgt << 1.atomic_weight; } else if (elem=
ent =3D=3D 2.name) { cout << title << 2.name; cout <=
< no << 2.name << is << 2.atomic_no; cout << wgt << 2.atomic_wei=
ght; } else if (element =3D=3D 3.name) { cout << tit=
le << 3.name; cout << no << 3.name << is << 3.atomic_no; =
cout << wgt << 3.atomic_weight;} else if (element =3D=3D 3.n=
ame) { 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.name; =
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.ato=
mic_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=
|