I want to link my main item to a 3 other ones at dif places lets call the others 1, 2 and 3.
How would i go about doing that?
Printable View
I want to link my main item to a 3 other ones at dif places lets call the others 1, 2 and 3.
How would i go about doing that?
I would try to help you, but I do not know what you are talking about.
Well you have ur first *main* part of the program it does stuff I give the user options to hit 1, 2 or 3 and when they hit them I want it to go to one of the less important parts.
Go different places, as in call different functions?
Is that what you are talking about?Code:#include <iostream>
using namespace std;
void function1();
void function2();
void function3();
int main()
{
cout << "Enter a number (1-3)" << endl;
int iNumber;
cin >> iNumber;
if(iNumber == 1)
function1();
else if(iNumber == 2)
function2();
else if(iNumber == 3)
function3();
else
cout << "You did not enter a valid number" << endl;
return 0;
}
void function1()
{
cout << "You hit 1" << endl;
}
void function2()
{
cout << "You hit 2" << endl;
}
void function3()
{
cout << "You hit 3" << endl;
}
like...... you have all the code for main k.... then it says like hit 1 to turn left 2 to go straight or 3 to jump up and down
there is already lots of code so i want to go to a new page for each so i would????????
Turn what left? You are not being very clear...
plz elaborate on what you are talking about so we can help you.
tell us what you are trying to do and what part of the program is giving you trouble. maybe show us some code.
it says:
cout << "You can:\n1 = Turn left\n2 = Turn right\n3 = Walk straight.\n";
cin number;
if (number == 1)
then I want it if they type 1 they go to like a dif. script page to make it less crowded and
if (number == 2)
a dif. one then the other 2.
and so on
first of all you cant put cin number;, because you need the overload. Use this instead:
now the next thing, all you need to do is make some if statements to see what the user pressed. Then call the appropriate functions to what the user wants to do.Code:cin>>number;
yeah my cin i did wrong on here but not on the thing...... but guys listen.... I want it so
what they choose a bunch of dif. things will happen for each not the same for each.
Basically you want to consturct functions. here is how to do it:
When this is run if you enter a 1 it will say "alialty alah"....Code:#inlcude <iostream.h>
void func1()
{
cout<<"alialty alah";
}
void func2()
{
cout<<"bliblty blah";
}
void func3()
{
cout<<"dlidlty dlah";
}
void main()
{
int choice;
cout<<"Enter 1 to do function 1. enter 2 to do function 2...";
cin<<choice;
if(choice==1)
func1();
i f(choice==2)
func2();
if(choice==3)
func3();
}
You said something about clearing. do you mean clearing the screen? if so include the stdlib.h library and do this when you want to clear system("CLS");
The other thing you can do is make a library. you just make functions and stcick them in a header file, and you can call the function just as if it were written at the top of your code.
Gr3g
I would use a case statement since it'll be easier to add in extra features later on and plus its easier to read than 3 if statements.
Of course you would have to define func1() and so on like stated before but that is probally the best way to do it.Code:#include <iostream>
int main()
{
int x;
cin >> x;
switch(x) {
case 1:
func1();
break;
case 2:
func2();
break;
case 3:
func3();
break;
default:
cout << "not a choice! ";
}
}//end main()
-Dennis
he wants to use gotoxy() to move something right when 1 is hit i dont know how to do it but i know thats what you do
Look up the function clrscr(). It'll clear the screen so it looks like a new console window. But, if you need to have a new window it's gonna be more advanced.
Theres stuff on clearing the screen in the FAQ.
Also look at the source on this website which has some stuff movement examples that someone put up.
Also you probably want to put the switch and input into a loop