i need this code to return to the question if you didnt type yes/no. if you type inventory it just says your inventory and pauses and closes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int main(){
srand(time(0)); /// Random number generator based on the cpu's time.
r = 1+rand()% 1; /// It can only go up to ten, At the moment.
if(r == 1){
cout<<"if you type in inventory when you can type it tells\nyou your inventory"<<endl;
cout<<"\n\n"<<endl;
cout << "You awake in a humid forest.\nYou see two wolves fighting over a piece of meat,\nthey look angry.\nYou know that wolves may attack if you make sudden movements.\nYou slowly arise to see both of the wolves are staring at you,\ntheir eyes burning holes through your skull.\n" << endl;
system("pause");
cout <<"Beside you is a stick that looks to have a sharp tip, use the stick, yes/no?"<<endl;
items = items + stick;
/// function for inventory
cin>>y;
if(inventory==y){
cout<<items<<endl;
}
system("pause");
}
DO NOT USE GOTO!!!! it can make for confusing and poor code. the second way can be a do while loop instead (or recursive functions, but thats overkill for something this small)
/// function for inventory
/// cin>>y
/// if(inventory==y){
///cout<<items<<endl;
///}
///system("pause");
int main(){
srand(time(0)); /// Random number generator based on the cpu's time.
r = 1+rand()% 1; /// It can only go up to ten, At the moment.
if(r == 1){
cout<<"if you type in inventory when you can type it tells\nyou your inventory"<<endl;
cout<<"\n\n"<<endl;
cout << "You awake in a humid forest.\nYou see two wolves fighting over a piece of meat,\nthey look angry.\nYou know that wolves may attack if you make sudden movements.\nYou slowly arise to see both of the wolves are staring at you,\ntheir eyes burning holes through your skull.\n" << endl;
system("pause");
cout <<"Beside you is a stick that looks to have a sharp tip, use the stick, yes/no?\nPlease type 1 for yes and 2 for no."<<endl;
items = items + stick;
/// function for inventory
while(response == Y ){
cin>>y,response;
if(inventory==y){
cout<<items<<endl;
}
}
if(YN == 1){
cout<<"you grab the stick and stab one of the wolves as they bound for you."<<endl;
}
}
system("pause");
heres my code with it edited a lil but its still broke.
this statement is the same as: while(y != no){ ect
i couldn't find a link on the comma operator, i'll have to demonstrate it myself:
the comma operator is a binary operator, it takes two expressions, evaluates them both, and the big expression evaluates to the same as the right operand.
example: (x=0) , (y=3); is the same as x = 0; y = 3;
z = (x = 0) , (y = 3); will evaluate to the same result as: x = 0; z = (y = 3);
one step further: z = ( std::cin>>x) , (y = x+3) ;, will give the same result as: std::cin>>x; z = (y = x+3);
since the comma operator evaluates to its right operand, when you combine two or more comma operators, they will evaluate to the rightmost operand: z = (std::cin>>x) , (y = x+3) , ( n = std::pow(y,5) ) , (std::cout<<n) , (n);
will evaluate to the same as:
1 2 3 4 5
std::cin>>x;
y = x+3;
n = std::pow(y,5);
std::cout<<n;
z = n;
finally, using the comma operator heavily can cost loss in readability, while using it rarely in a smart way can give considerable benefits, like in loops: