nie moge skompilowac i pokazuje mi dziwne errory z prawidlowymi (wedlug mnie i ksiazki) linijkami
Ostatnio zmodyfikowano 2013-03-30 17:16
sasa32010 Temat założony przez niniejszego użytkownika |
nie moge skompilowac i pokazuje mi dziwne errory z prawidlowymi (wedlug mnie i ksiazki) linijkami » 2013-03-18 17:47:37 nie moge skompilowac programu co zrobic kod to
#include <iostream> #include <cstdlib> #include <string> #include <ctime>
using namespace std;
int main() { srand( time( NULL ) ); int zycie_bohatera = 150; int atak_bohatera; int liczba =( rand() % 3 ) + 1; string imie; cout << "witaj w blood arena" << endl; cout << "podaj swoje imie" << endl; cin >> imie; cout << "dziekuje " << imie << endl << endl; cout << "walczysz z : "; switch( liczba ) { case 1: cout << "szkieletem" << endl << endl << endl; cout << "start" << endl << endl; int zycie_szkieleta = 140; int atak_szkieleta; do { cout << imie << " " << zycie_bohatera << endl; cout << "szkielet " << zycie_szkieleta << endl << endl; atak_szkieleta =( rand() % 21 ) + 1; zycie_bohatera = zycie_bohatera - atak_szkieleta; cout << "- " << atak_szkieleta << endl << endl; cout << imie << " " << zycie_bohatera << endl; cout << "szkielet " << zycie_szkieleta << endl << endl; atak_bohatera =( rand() % 20 ) + 1; zycie_szkieleta = zycie_szkieleta - atak_bohatera; cout << "- " << atak_bohatera << endl << endl; } while( zycie_szkieleta <= 1, zycie_bohatera <= 1 ); if( zycie_szkieleta >= 1 ) cout << "wygrales"; else cout << "przeglales"; break; case 2: cout << "zombie" << endl << endl << endl; cout << "start" << endl << endl; int zycie_zombie = 200; int atak_zombie; do { cout << imie << " " << zycie_bohatera << endl; cout << "zombie " << zycie_zombie << endl << endl; atak_zombie =( rand() % 15 ) + 1; zycie_bohatera = zycie_bohatera - atak_zombie; cout << "- " << atak_zombie << endl << endl; cout << imie << " " << zycie_bohatera << endl; cout << "zombie " << zycie_zombie << endl << endl; atak_bohatera =( rand() % 20 ) + 1; zycie_zombie = zycie_zombie - atak_bohatera; cout << "- " << atak_bohatera << endl << endl; } while( zycie_zombie <= 1, zycie_bohatera <= 1 ); if( zycie_zombie >= 1 ) cout << "wygrales"; else cout << "przeglales"; break; case 3: cout << "pajakiem" << endl << endl << endl; cout << "start" << endl << endl; int zycie_pajaka = 100; int atak_pajaka; do { cout << imie << " " << zycie_bohatera << endl; cout << "pajak " << zycie_szkieleta << endl << endl; atak_pajaka =( rand() % 25 ) + 1; zycie_bohatera = zycie_bohatera - atak_pajaka; cout << "- " << atak_pajaka << endl << endl; cout << imie << " " << zycie_bohatera << endl; cout << "pajak " << zycie_pajaka << endl << endl; atak_bohatera =( rand() % 20 ) + 1; zycie_pajaka = zycie_pajaka - atak_bohatera; cout << "- " << atak_bohatera << endl << endl; } while( zycie_pajaka <= 1, zycie_bohatera <= 1 ); if( zycie_pajaka >= 1 ) cout << "wygrales"; else cout << "przeglales"; break; } return 0; }
errory wychodza takie : In function 'int main()': 58 7 [Error] jump to case label [-fpermissive] 33 7 [Error] crosses initialization of 'int zycie_szkieleta' 87 7 [Error] jump to case label [-fpermissive] 62 7 [Error] crosses initialization of 'int zycie_zombie' 33 7 [Error] crosses initialization of 'int zycie_szkieleta' jak pisze o zycie_szkieleta i o zycie_zombie to czemu nic nie napisalo o zycie_pajaka za kazda pomoc dziekuje :-) |
|
pekfos |
» 2013-03-18 17:53:43 switch( x ) { case 1: { } break; } |
|
sasa32010 Temat założony przez niniejszego użytkownika |
» 2013-03-18 17:56:26 dzieki
ale w kalkulatorze jak pisalem to nie trzeba bylo {} w case
teraz dziala dzieki :-)
a jak napisac w while() ze albo to albo to |
|
pekfos |
» 2013-03-18 18:03:12 |
|
sasa32010 Temat założony przez niniejszego użytkownika |
» 2013-03-18 18:11:20 co jest zlego z petla ze nie petli
do { cout << imie << " " << zycie_bohatera << endl; cout << "szkielet " << zycie_szkieleta << endl << endl; atak_szkieleta =( rand() % 21 ) + 1; zycie_bohatera = zycie_bohatera - atak_szkieleta; cout << "- " << atak_szkieleta << endl << endl; cout << imie << " " << zycie_bohatera << endl; cout << "szkielet " << zycie_szkieleta << endl << endl; atak_bohatera =( rand() % 20 ) + 1; zycie_szkieleta = zycie_szkieleta - atak_bohatera; cout << "- " << atak_bohatera << endl << endl; } while( zycie_szkieleta >= 1 || zycie_bohatera >= 1 );
daje jedna runde i przestaje
wedlug mnie dobra petla |
|
domin568 |
» 2013-03-23 14:22:20 Jeżeli się nie pętli to znaczy że problem jest z warunkiem . Analizowalem pobieżnie kod i pętla jest dobra tylko popracuj nad "while" i powinno pójść :) . |
|
sasa32010 Temat założony przez niniejszego użytkownika |
» 2013-03-27 15:27:16 co jest zlego z warunkiem
operatory sa dobre
nazwy zmiennych sa dobre
sa wlasciwie zastosowane
niewiem co jest zle
:-( |
|
Fores |
» 2013-03-28 16:50:11 W przypadku pajaka: cout << "pajakiem" << endl << endl << endl; cout << "start" << endl << endl;
int zycie_pajaka = 100; int atak_pajaka;
do { cout << "Zycie bohatera " << imie << " " << zycie_bohatera << endl; cout << "Zycie pajaka " << zycie_pajaka << endl << endl; atak_pajaka =( rand() % 25 ) + 1; zycie_bohatera = zycie_bohatera - atak_pajaka; cout << "Atak pajaka " << atak_pajaka << endl << endl; cout << "Zycie " << imie << " " << zycie_bohatera << endl; cout << "Zycie pajaka " << zycie_pajaka << endl << endl; atak_bohatera =( rand() % 20 ) + 1; zycie_pajaka = zycie_pajaka - atak_bohatera; cout << "Atak bohatera " << atak_bohatera << endl << endl; } while( zycie_pajaka >= 1 && zycie_bohatera >= 1 );
if( zycie_pajaka <= 1 ) cout << "wygrales"; else cout << "przeglales"; Warunkiem w while ma byc AND, a nie OR, bo wtedy to nie ma zadnego sensu. I w IFie warunek ma byc odwrotny (jak pajak ma zycie mniejsze od 1 to ty wygrywasz, a nie odwrotnie) Ogolnie to cala petla jest zle napisana. Zauwaz co sie dzieje gdy 'bohater' przegrywa. |
|
« 1 » 2 |