Help In Looping

Can anyone help me figure out passing by function for a loop?
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
int element(string Name, double Number, int Group, int Period, string Charge, string Formula, double Mass,double& Neutrons)
{int x,y;
 cout<<"Group no:";
 cin>>x;
cout<<"Period no:";
cin>>y;
if ((x == 1) && (y == 1) )
{
Name ="hydrogen";
Number = 1;
Group = 1;
Period = 1;
Formula = "H";
Charge = "1+";
Mass = 1.01;
Table (Name, Number, Group, Period, Formula, Charge, Mass, Neutrons );
else if ((x ==s ) ||( y==s )||(x <=0 ) ||( y<=0 )||(x > 18 ) ||( y> 4 ))
 {
 cout<< "Unrecognized command.\n";
 element(Name,Number,Group,Period,Charge,Formula,Mass,Neutrons);
 }
else if(cont==N)
{menu();}


	return cont;}


1
2
3
4
5
6
7
8
9
10
11
12
13
int Table(string Name, double Number, int Group, int Period, string Formula, string Charge, double Mass,double& Neutrons)
{do{
Neutrons = (Mass - Number);
system ( "cls" );
cout<< "Element Name:  " <<Name<<"\n";
cout<<"Continue?(Y/N) :"<<endl;
		cin>>cont ;	

{element(Name,Number,Group,Period,Charge,Formula,Mass,Neutrons);}

}while(cont!=N||cont!=n);
return cont;
}


Here's what I get when I run the code:
when i enter y/n,the loop still continue.
when i enter s for x,the whole program loop.

Thanks in advanced.
Change statement

while(cont!=N || cont!=n);

to

while(cont!=N && cont!=n);
Tried that,but still looping.What I am trying to do is set a condition for the part 2 of the code but seems like it doesn't work that way?

And one more thing,else if ((x ==s ) ||( y==s )when I enter a char for x,the whole program goes into an infinity loop.Any help?
Table (Name, Number, Group, Period, Formula, Charge, Mass, Neutrons )

you should but them in the same order as

element(string Name, double Number, int Group, int Period, string Charge, string Formula, double Mass,double& Neutrons)
and what do you mean with the s?

else if ((x ==s ) ||( y==s )||(x <=0 ) ||( y<=0 )||(x > 18 ) ||( y> 4 ))

you should but it within quotes 's'
I am just calling the function.Will it have any implication if i retain the same format?
It matches their types and in most cases their order.
oh,i meant char.When users are prompted to enter the x and y,if they enter a char,I want the system to stop.
while(cont!='N'||cont!='n');
or
while(cont='Y'||cont='y');
while(cont='Y'||cont='y');,returns an error,must be modifiable.One more thing,can I set a condition where if when user input other than integer,the program will stop?
yes you can, and it is called Exception handling but you need to write one more function to do it.
Okay,but the loop thing still ain't working.Is it because the loop involves 2 functions?
oops my bad, while(cont=='Y'||cont=='y');
Last edited on
Nope,still the same,it still loops.
why you are returning cont? just get rid of it
i was testing something previously.I changed it to return 0
You may want to declare what cont IS, in your functions.
I declared cont as char,at the top of the code.These 2 functions are just part of the whole code which I am having trouble with.The code is pretty lengthy.
Topic archived. No new replies allowed.