I'm trying to create a simple
while()
-loop and keep it running as long as the user does not enter '0'. I have succeeded with this task before, but now I can't remember how.
What I'm trying to do... (this is just an example)
Main function:
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 27 28 29 30 31 32 33 34
|
#include <iostream>
#include <wiondows.h>
using namespace std;
void myMeny(int x);
void menyOne();
int main()
{
int x;
while(x!=0) //while 'x' is not equal to '0'
{
myMeny(x);
if(x = 1)
{
system("cls");
menyOne();
} //END if
// .... more if-statements not shown in this example
else
{
cout << "Wrong number. Try again.";
Sleep(1000);
system("cls");
} //END else
} //END while
} //END main
|
myMeny function:
1 2 3 4 5 6 7 8 9 10
|
void myMeny(int x)
{
cout << "Show meny one : 1\n";
cout << "Exit application : 0\n";
//.... more options not shown in this example
cin >> x;
} //END myMeny
|
menyOne function:
1 2 3 4 5 6 7 8
|
void menyOne()
{
cout << "This is meny one.";
Sleep(1000);
// How do I return to the main function??
} //END menyOne
|
I suppose there is more than one problem with my code.
*Key question:
No matter what I put in, the
if(x=1)
always return true. The else-statement is never shown. I tried changing it to
if(x==1)
but when I put in 1, the else is shown. And the loop breaks after the else statement is shown. Why?
And how do I return to my main function from my menyOne -function?
Thanks in advance!
I will continue to update this topic to give as much information as possible.
EDIT:
I was having a hard time to figure out what to title this topic. If you have a better suggestion, please tell me. =)