Dzień dobry,
mam pytanie otóż mam problem taki jak w temacie. funkcja menu odpala gre, a po skończeniu gry funkcja gra odpala funkcje menu. Jednak funkcja gra uważa, że funkcja menu pojawia się pierwszy raz w programi(jest zadeklarowana pod nią)zamiana miejsc nic nie daje.Potrzebuje pomocy
Pokaż kod.
Słowo klucz dla google'a: forward declaration
int factorial_b(int);
int factorial_a(int n){
return n ? factorial_b(n-1) * n : 1;
}
int factorial_b(int n){
return n ? factorial_a(n-1) * n : 1;
}
http://melpon.org/wandbox/permlink/xJamUZKj0pRz9yV2
Przy czym: w Twoim przypadku to prawie na pewno jest złe rozwiązanie. Raczej potrzebujesz pętli głównej programu.
#include <iostream>
#include <cstring>
#include <conio.h>
#include <cstdlib>
#include <fstream>.
using namespace std;
#include "windows.h"
void gotoxy(int x, int y)
{
COORD c;
c.X = x - 1;
c.Y = y - 1;
SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
}
char *tr(char *str)
{
static char buff[256];
char cp[]="\245\206\251\210\344\242\230\276\253\244\217\250\235\343\340\227\275\215ąćęłńóśżźĄĆĘŁŃÓŚŻŹ";
if(strlen(str)>=sizeof(buff)) return str;
char *bf=buff;
while(*str)
{
char *pos=strchr(cp+18,*str);
(bf++)=pos?(pos-18):*str;
++str;
}
*bf=0;
return buff;
}
int menu_zmienna;
string napis;
void menu(),gra()
gra ()
{
int x1,x2,x3,y1,y2,y3,xp1,xp2,xp3,yp1,yp2,yp3,tura,hp1,hp2,lx1,lx2,lx3,g1,g2,p1,p2,z1,z2,w1,w2,z11,z22,ly1,ly2,ly3,l1,l2,l3,lxx1,lxx2,lxx3,lyy1,lyy2,lyy3,xpp1,xpp2,xpp3,ypp1,ypp2,ypp3,ll1,ll2,ll3;
float x,xx,xxx,y,yy,yyy,m1,m2,m3,n1,n2,n3;
tura=0;
xp1=0;
xp2=0;
xp3=0;
yp1=0;
yp2=0;
yp3=0;
hp1=60;
hp2=60;
l1=0;
l2=0;
l3=0;
p1=50;
p2=50;
z1=0;
z2=0;
z11=0;
z22=0;
lxx1=0;
lxx2=0;
lxx3=0;
lyy1=0;
lyy2=0;
lyy3=0;
xpp1=0;
xpp2=0;
xpp3=0;
ypp1=0;
ypp2=0;
ypp3=0;
z11=0;
z22=0;
ll1=0;
ll2=0;
ll3=0;
g1=0;
g2=0;
while(hp1<120 && hp2<120)
{
w1=999999999;
w2=999999999;
lx1=0;
lx2=0;
lx3=0;
ly1=0;
ly2=0;
ly3=0;
tura++;
while(w1>g1)
{
if(tura==1)
{
z11=10;
}
g1=z11+p1;
z1=g1;
cout<<"Tura "<<tura<<" gracza 1"<<endl;
cout<<"Masz "<<z1<<tr(" złota")<<endl;
cout<<tr("Podaj wielkość armi 1.")<<endl;
cin>>x1;
x=x1+xp1;
z1=z1-x1;
cout<<"Masz "<<z1<<tr(" złota")<<endl;
cout<<tr("Podaj wielkość armi 2.")<<endl;
cin>>x2;
xx=x2+xp2;
z1=z1-x2;
cout<<"Masz "<<z1<<tr(" złota")<<endl;
cout<<tr("Podaj wielkość armi 3.")<<endl;
cin>>x3;
xxx=x3+xp3;
z1=z1-x3;
w1=x1+x2+x3;
system("cls");
}
z11=z1;
while(w2>g2)
{
if(tura==1)
{
z22=10;
}
g2=z22+p2;
z2=g2;
cout<<"Tura "<<tura<<" gracza 2"<<endl;
cout<<"Masz "<<z2<<tr(" złota")<<endl;
cout<<tr("Podaj wielkość armi 1.")<<endl;
cin>>y1;
y=y1+yp1;
z2=z2-y1;
cout<<"Masz "<<z2<<tr(" złota")<<endl;
cout<<tr("Podaj wielkość armi 2.")<<endl;
cin>>y2;
yy=y2+yp2;
z2=z2-y2;
cout<<"Masz "<<z2<<tr(" złota")<<endl;
cout<<tr("Podaj wielkość armi 3.")<<endl;
cin>>y3;
yyy=y3+yp3;
z2=z2-y3;
w2=y1+y2+y3;
system("cls");
}
z22=z2;
xp1=0;
xp2=0;
xp3=0;
yp1=0;
yp2=0;
yp3=0;
if((x+y)>=1)
{
m1=(xx)/(x+y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3;
getch();
system("cls");
}
cout<<"KONIEC GRY"<<endl;
getch();
system("cls");
menu();
}
menu()
{
while (menu_zmienna!=1 && menu_zmienna!=2 && menu_zmienna!=3 && menu_zmienna!=4)
{
cout<<"MENU"<<endl;
cout<<endl;
cout<<tr("gra-1")<<endl;
cout<<"instrukcja-2"<<endl;
cout<<"ustawienia-3"<<endl;
cout<<tr("wyjście-4")<<endl;
cin>>menu_zmienna;
if (menu_zmienna!=1 && menu_zmienna!=2 && menu_zmienna!=3 && menu_zmienna!=4)
{
system("cls");
cout<<tr("Zła wartość")<<endl;
cout<<endl;
}
else
{
system("cls");
}
}
if ( menu_zmienna==1 )
{
gra();
menu_zmienna=0;
}
if(menu_zmienna==2)
{
}
if (menu_zmienna==4)
{
exit(0);
}
}
int main(int argc, char *argv[])
{
menu();
}
także tego .... xD
int x1,x2,x3,y1,y2,y3,xp1,xp2,xp3,yp1,yp2,yp3,tura,hp1,hp2,lx1,lx2,lx3,g1,g2,p1,p2,z1,z2,w1,w2,z11,z22,ly1,ly2,ly3,l1,l2,l3,lxx1,lxx2,lxx3,lyy1,lyy2,lyy3,xpp1,xpp2,xpp3,ypp1,ypp2,ypp3,ll1,ll2,ll3;
float x,xx,xxx,y,yy,yyy,m1,m2,m3,n1,n2,n3;
tura=0;
xp1=0;
xp2=0;
xp3=0;
yp1=0;
yp2=0;
yp3=0;
hp1=60;
hp2=60;
l1=0;
l2=0;
l3=0;
p1=50;
p2=50;
z1=0;
z2=0;
z11=0;
z22=0;
lxx1=0;
lxx2=0;
lxx3=0;
lyy1=0;
lyy2=0;
lyy3=0;
xpp1=0;
xpp2=0;
xpp3=0;
ypp1=0;
ypp2=0;
ypp3=0;
z11=0;
z22=0;
ll1=0;
ll2=0;
ll3=0;
g1=0;
g2=0;
HE HE HE
- Zapoznać się z pojęciem formatowania kodu: http://4programmers.net/Forum/998482
- Zapoznać się z pojęciem pętla
- Wywalić to wszystko
- Napisać od nowa.