Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- string tabPays[10];
- float tabCoutInit[10];
- void lireInfoUtilisateur(string &nomPays, float &dureeAppel);
- int initDonnees(string nomFichier);
- int main() {
- string nomFichier = "data.txt";
- int nbrPays = 0; // nombre de pays dans le fichier data.txt
- // Initailisation des donnees des tableaux
- int nbPays = initDonnees(nomFichier);
- // Lire les information utlisateur
- float dureeAppel;
- string nomPays;
- lireInfoUtilisateur(nomPays, dureeAppel);
- // Retrouver le cout unit du pays
- bool trouve = false;
- for (int i = 0; i < nbPays; i++)
- {
- if (nomPays == tabPays[i])
- {
- trouve = true;
- float coutAppel = tabCoutInit[i] * dureeAppel;
- cout << "Le pays est : " << tabPays[i] << " cout initiale est : " << tabCoutInit[i] << " votre appel coute:" << coutAppel << endl;
- }
- }
- if (trouve == false)
- {
- cout << "too bad!" << endl;
- }
- //float coutUnitPays = coutParPays(nomPays, nbrPays);
- system("pause");
- return 0;
- }
- void lireInfoUtilisateur(string &nomPays, float &dureeAppel)
- {
- cout << "Vous voulez appeler quel pays ? ";
- cin >> nomPays;
- cout << "\nDuree de votre appel ?";
- cin >> dureeAppel;
- }
- int initDonnees(string nomFichier)
- {
- int i = 0;
- ifstream fluxsortie("data.txt");
- if (fluxsortie)
- {
- while (!fluxsortie.eof())
- {
- fluxsortie >> tabPays[i] >> tabCoutInit[i];
- if (!fluxsortie.eof())
- {
- i++;
- }
- }
- }
- else
- {
- return -1;
- }
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement