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.
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.
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.
#include <iostream>
#include <string>
#include <stdlib.h>
usingnamespace 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.
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.