few questions on bool

Hi,

I am following an online course on c++ and I don't think it covers everything. I am writting a speed dating program just to practice with coding.

I have a counter that measures how many women visit the table, but I also want to vote on each contestant if they were liked or not and this is what I can<t figure out.

This is what I have so far.

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
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;
int ajouteUn(int nombreRecu)

{

    int valeur(nombreRecu + 1);


    return valeur;

}
int main()
{

    cout << "Bonjours!" << endl;
    cout << "" << endl;
    cout << "Je suis Christopher. ";
    cout << "" << endl;
    cout << "" << endl;
    cout << "Quel est votre prenom? ";
    string nomUtilisateur(" aucun");
    cin >> nomUtilisateur ;
    cout << "" << endl;
    cout << "Bienvenue dans votre Univers " << nomUtilisateur << "." << endl;
    cout << "" << endl;
    cout << "" << endl;
    cout << "Ce programme me permettra d'approfondir mes connaissances en programmation C++. ";
    cout << "" << endl;
    cout << "" << endl;
    cout << "J'aurai besoin de votre aide. ";
    cout << "" << endl;
    cout << "" << endl;
    cout << "Inscrivez le nombre indiquant votre age. ";
    cout << "" << endl;
    int ageUtilisateur (0);
    cin >> ageUtilisateur  ;
    if (ageUtilisateur >= 19)
    {
        cout << ageUtilisateur << " ans? Parfait, poursuivons. " << endl;
    }
    else
    {
        cout << ageUtilisateur << " ans? Ah, Dommage! Je ne crois pas que vous etes en mesure m'aider." << endl;
        exit (EXIT_FAILURE);
    }
    cout << "" << endl;
    cout << "" << endl;
    double shirt(0), jean(0);
    cout << "Veuillez vous choisir un ensemble avec un budget de 50$" << endl;
    cout << "" << endl;
    cout << "Quel est le prix de ce shirt? : ";
    cin >> shirt;
    cout << "" << endl;
    cout << "Et cette paire de jean? : ";
    cin >> jean;
    cout << "" << endl;
    double const resultat(shirt + jean);
    double const taxe((shirt+jean)*.13);
    double const total((shirt+jean)*.13 + (shirt+jean));
    cout << shirt << " + " << jean << " = " << resultat << " $" << endl;
    cout << taxe << "$ de taxe." << endl;
    cout << total << "$ au total." <<endl;
    cout << "" << endl;
    if (total > 50)
    {
        cout << "Vous n'avez pas les fonds suffisant pour cet ensemble." << endl;
    }
    else if (total <= 50)
    {
        cout << "Vous avez les fonds suffisant." << endl;
    }
    cout << "" << endl;
    if (total <= 50)
    {
        cout << "Maintenant que vous etes mieux vetue, dirigeons nous vers la salle a dinner." << endl;
        cout << "Assoyez vous, votre date arrivera sous peu." << endl;
    }
    else
    {
        cout << "Revenez un autre jours." << endl;
    }
    cout << "" << endl;

    cout << "19h00, début du speed dating, Voici votre premiere date. A tout les 5 minutes il y a une cloche et les femmes change de table." << endl;
    int a(0),b(0);
    cout << "Valeur de a : " << a << endl;
    cout << "Valeur de b : " << b << endl;
    a = ajouteUn(a); //Appel de la fonction
    cin >> b;
    cout << "Valeur de a : " << a << endl;
    cout << "Valeur de b : " << b << endl;

    return 0;
}
Your program appears to process a single user. But, you need to handle multiple users. To do this, you need:
1. To run the processing section in a loop, once for each user
2. You need to arrange for that data to be stored, so you can process it later.
Hello chris442,

I took the liberty to rearrange your program so I could figure out what it was doing. A few blank lines makes it easier to read and that is one big point.

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;  // <--- Best not to use.  Mieux vaut ne pas utiliser.

void Opening()
{
	cout << "Bonjours!" << endl;
	cout << '\n' << endl;  // <--- C'est tout ce dont vous avez besoin.
	//cout << "" << endl;  // <--- Pas besoin.
	cout << "Je suis Christopher. ";
	cout << '\n' << endl;
	//cout << "" << endl;
	cout << "Quel est votre prenom? ";
}

void Message(std::string& nomUtilisateur)
{
	cout << "" << endl;
	cout << "Bienvenue dans votre Univers " << nomUtilisateur << "." << endl;
	cout << '\n << endl;
	//cout << "" << endl;
	cout << "Ce programme me permettra d'approfondir mes connaissances en programmation C++. ";
	cout << '\n' << endl;
	//cout << "" << endl;
	cout << "J'aurai besoin de votre aide. ";
	cout << '\n' << endl;
	//cout << "" << endl;
	cout << "Inscrivez le nombre indiquant votre age. ";
	cout << '\n' << endl;
}

int ajouteUn(int nombreRecu)

{
	int valeur(nombreRecu + 1);

	return valeur;  // <--- Or could be just "return ++nombreRecu;". The ++ at the beginning adds one before the return is done.
}

int main()
{
//******  varié  *******
	string nomUtilisateur(" aucun");  // no

	Opening();

	cin >> nomUtilisateur;

	Message(nomUtilisateur);

//******  varié  *******
	int ageUtilisateur(0);

	cin >> ageUtilisateur;

	if (ageUtilisateur >= 19)
	{
		cout << ageUtilisateur << " ans? Parfait, poursuivons. " << endl;
	}
	else
	{
		cout << ageUtilisateur << " ans? Ah, Dommage! Je ne crois pas que vous etes en mesure m'aider." << endl;
		exit(EXIT_FAILURE);
	}

	cout << '\n' << endl;  // <--- Modifié.
	//cout << "" << endl;    // <--- Pas besoin maintenant.

//******  varié  *******
	double shirt(0), jean(0);

	cout << "Veuillez vous choisir un ensemble avec un budget de 50$" << endl;
	cout << '\n' << endl;
	cout << "" << endl;
	cout << "Quel est le prix de ce shirt? : ";
	cin >> shirt;
	cout << '\n' << endl; 
	//cout << "" << endl;
	cout << "Et cette paire de jean? : ";
	cin >> jean;
	cout << '\n' << endl;
	//cout << "" << endl;

//******  varié  *******
	// <--- Changed. Modifié. Je voulais que vous voyiez comment cela devrait être fait.
	double const TAXE(0.13);  // <--- Je préférerais que ce soit tout en haut de la fonction ou du fichier où il est plus facile de trouver et de changer.
	// <--- Ceux-ci n'ont pas besoin d'être une constante.
	double resultat(shirt + jean);
	double taxe((shirt + jean) * TAXE);
	double  total(shirt + jean + taxe);

	cout << shirt << " + " << jean << " = " << resultat << " $" << endl;
	cout << taxe << "$ de taxe." << endl;
	cout << total << "$ au total." << endl;
	cout << "" << endl;

	if (total > 50)
	{
		cout << "Vous n'avez pas les fonds suffisant pour cet ensemble." << endl;
	}
	else if (total <= 50)
	{
		cout << "Vous avez les fonds suffisant." << endl;
	}

	cout << '\n' << endl;
	//cout << "" << endl;

	if (total <= 50)
	{
		cout << "Maintenant que vous etes mieux vetue, dirigeons nous vers la salle a dinner." << endl;
		cout << "Assoyez vous, votre date arrivera sous peu." << endl;
	}
	else
	{
		cout << "Revenez un autre jours." << endl;
	}

	cout << '\n' << endl;
	//cout << "" << endl;

	cout << "19h00, début du speed dating, Voici votre premiere date. A tout les 5 minutes il y a une cloche et les femmes change de table." << endl;

	// <--- What is this section for?  A quoi sert cette section?
//******  varié  *******
	int a(0), b(0);

	cout << "Valeur de a : " << a << endl;
	cout << "Valeur de b : " << b << endl;
	a = ajouteUn(a); //Appel de la fonction  Call of the function
	cin >> b;
	cout << "Valeur de a : " << a << endl;
	cout << "Valeur de b : " << b << endl;

	return 0;
} 


i put the opening of "main" into two functions. Not necessary, but it gives you an idea what can be done. This concept could also be done in other places in the program. A Good example is http://www.cplusplus.com/forum/beginner/244319/ and the response by JLBorges.

Through the program I have made comments about what I have changed or suggested.

This section of the program, near the bottom, that I do not understand what it is doing or what it is for:
1
2
3
4
5
6
7
8
9
10
	// <--- What is this section for?  A quoi sert cette section?
//******  varié  *******
	int a(0), b(0);

	cout << "Valeur de a : " << a << endl;
	cout << "Valeur de b : " << b << endl;
	a = ajouteUn(a); //Appel de la fonction  Call of the function
	cin >> b;
	cout << "Valeur de a : " << a << endl;
	cout << "Valeur de b : " << b << endl;

This is a good place to call a function to rate the experience. Not sure if you would want to make the result a bool or a number.

I have a counter that measures how many women visit the table

I must have missed this part. When you increase the counter you could follow this with a call to a function to rate the experience.

Lastly kbw makes two good points that you need to address.

Hope that helps,

Andy
Thanks, I will look into the details and understand what you did. The last section is a fictional speed dating calculation that says every five minutes there is a new contestant and the user has to vote on each. one counter says how many he received at his table and the second one is those he was interested in.

I am only one week into c++ and I know I have lots to learn on my own but anything helps.
Last edited on
Topic archived. No new replies allowed.