Program flow

Hey there!
When coding programs and trying to separate them into functions I usually get stuck to make the program flow from function to function. I really want to know how you guys code the programs, how do you separate them and make them work? Do you make functions called: "Get", "Set"? Here's something I was coding just to try to learn how to make the program move with functions.

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  // MathGame.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

using namespace std;

int outputGeneratedNumbers(int x, int y); //prototype

int generateNumber(int currentLevel)
{
	srand(time(0));
	int numberOne = 0;
	int numberTwo = 0;

	switch(currentLevel)
	{
	case 1:
		numberOne = +rand() % 50;
		numberTwo = +rand() % 50;
		break;
	case 2:
		numberOne = +rand() % 100;
		numberTwo = +rand() % 100;
		break;
	case 3:
		numberOne = +rand() % 150;
		numberTwo = +rand() % 150;
		break;
	case 4:
		numberOne = +rand() % 200;
		numberTwo = +rand() % 200;
		break;
	case 5:
		numberOne = +rand() % 250;
		numberTwo = +rand() % 250;
		break;
	case 6:
		numberOne = +rand() % 300;
		numberTwo = +rand() % 300;
		break;
	default:
		numberOne = +rand() % 300;
		numberTwo = +rand() % 300;
	}
	return outputGeneratedNumbers(numberOne, numberTwo);
}

char generateArithmetic()
{
	srand(time(0));

	char arithmetics[4] = { '*', '-', '+', '/' };
	int randIndex = +rand() % 4;
	cout << arithmetics[randIndex];

	return 0;
}

int outputGeneratedNumbers(int x, int y)
{
	cout << x << " " << y;
	return 0;
}

int checkLevel(int z)
{
	return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
	SetConsoleTitle(TEXT("Math Game"));
	string firstPlayer, secondPlayer;
	int firstPlayerPoints = 0, secondPlayerPoints = 0;
	int current_level;

	cout << "(Player1) Please input your name: ";
	cin >> firstPlayer;
	cout << "(Player2) Please input your name: ";
	cin >> secondPlayer;
	system("CLS");
	cout << "(" << firstPlayer << ")" << " Calculate the following: ";

	return 0;
}

hiya.
I'm not really sure what you mean sorry. I can see you've written 2 functions, one called "generateArithmetic" and one called "generateNumber", but you don't actually seem to use them at all.
Unfinished code. As you can see I can stuck. I just want to know the exact way how to make the program run with functions. What methods should I use?
Dude i'm not a mind reader.

1. You ask the user for 2 names. And that's it.
2. You have a function that generates a number based on a "current level". I dont know what that is.
3. you have another function that is supposed to return a character, but you always return zero.
4. you have another function that checks a level but does not.

So yea, I appreciate it's unfinished code, but based on the fact you've told us nothing and all the main is doing is asking for 2 strings (and none of your functions actually take 2 strings), what exactly do you want your program to do?
Last edited on
Umm

You define strings and have no string header the sting Libary is part of the C++ standard libary

And the flow of functions normally calls and returning the value and using it in main function or printing text from another function using void which returns nothing

So what is the purpose of the programme and I might be able to tell you how the flow of functions work
@mutexe:
I'm not trying to finish the code, nor trying to do something which I can't do in the code. I was just showing an example of functions going to other functions. I was just curious if I'm doing it 'right', I'm only asking more experienced programmers if they use typical functions to "get" values, "set" values (like classes), and what's the best method to return to something such as a function.
Topic archived. No new replies allowed.