Load from file will give random INT number

Pages: 123
My code is an example what you should do and not "copy paste this part and it will work"

I want that from the shop() function, go to the again();, which is after the shop().
You are calling your shop function either from again() or game().
How functions work in general:
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
#include <iostream>

void shop()
{
     std::cout << "I'm in shop now\n";
}

void again()
{
    std::cout << "Again() is running...\n";
    shop();
    std::cout << "Returned to again() after shopping\n";
    //again(); commented to make program terminate normally 
}

void game()
{
    std::cout << "game() is running...\n";
    shop();
    std::cout << "Returned to game() after shopping\n";
    again();
}

int main()
{
    std::cout << "program started\n";
    game();
    std::cout << "exiting...\n";
}
program started
game() is running...
I'm in shop now
Returned to game() after shopping
Again() is running...
I'm in shop now
Returned to again() after shopping
exiting...
http://ideone.com/9C9YKc
Last edited on
Thanks buddy! You solved my question!

Thank you very much! I don't know what to do in exchange!

Thanks for your time!
Private wrote:
Bro, thanks but I don't want to get pre-made as I wont learn anything off it. It is better when I learn the things step by step. Also, I think you haven't got my point.

I want that from the shop() function, go to the again();, which is after the shop().

It is fine that you want to do it on your own, but you will have to get used to learning to do things from reading and understanding someone else's code at some point because most libraries out there sometimes have poor documentation or no updated tutorials which requires you to read the code and figure out what it is doing.

As pointed out by others, your code is doing multiple calls that aren't needed and from what I can see game() and again() are identical functions. Part of learning is listening to others that know the language. I didn't make my code for you to use, but to learn by understanding my code and what it is doing. For example, my program does the exact same as yours, but does so with only one function call, but also gives the 'player' the ability to exit without clicking the close button. The code I showed can easily have a shop function added to it by simply removing the cases for buying and selling and turning it into a single case for calling shop where you can have code for buying items or selling pokemon.
Topic archived. No new replies allowed.
Pages: 123