Hey ! I'm new to the forums and new to C++ too, so I have a homework in which I have to make a program that will determine which of the 5 numbers the user enters is the lowest and the highest. My code goes like this :
//But : Créer un programme qui lit 5 entiers et qui dit lequel de ces entiers est le plus gros et le plus petit
//Auteur : Anthony Gauthier
//Date : 25 octobre 2012
#include <iostream>
int main()
{
usingnamespace std; //Ne pas a avoir a ecrire std::
setlocale (LC_ALL, ""); //Caractères accentués
int iNb1; //Variables utilisées
int iNb2;
int iNb3;
int iNb4;
int iNb5;
int iMax;
int iMin;
cout << "Veuillez entrer un premier nombre" << endl; //Demander à l'utilisateur un premier nombre
cin >> iNb1; //Prend en note le nombre entrer
cout << "Veuillez entrer un deuxième nombre" << endl; //Demander à l'utilisateur un deuxième nombre
cin >> iNb2; //Prend en note le nombre entrer
cout << "Veuillez entrer un troisième nombre" << endl; //Demander à l'utilisateur un troisième nombre
cin >> iNb3; //Prend en note le nombre entrer
cout << "Veuillez entrer un quatrième nombre" << endl; //Demander à l'utilisateur un quatrième nombre
cin >> iNb4; //Prend en note le nombre entrer
cout << "Veuillez entrer un cinquième nombre" << endl; //Demander à l'utilisateur un cinquième nombre
cin >> iNb5; //Prend en note le nombre entrer
system ("cls"); //Faire disparaître le texte à l'écran
if (iNb1<iNb2)iMax=iNb2; //Trouver le plus grand nombre
if (iNb1<iNb3)iMax=iNb3;
if (iNb1<iNb4)iMax=iNb4;
if (iNb1<iNb5)iMax=iNb5;
cout << "Le plus grand nombre est : " << iMax << endl; //Afficher le plus petit nombre
if (iNb1>iNb2)iMin=iNb2; //Trouver le plus petit nombre
if (iNb1>iNb3)iMin=iNb3;
if (iNb1>iNb4)iMin=iNb4;
if (iNb1>iNb5)iMin=iNb5;
cout << "Le plus petit nombre est : " << iMin << endl; //Afficher le plus petit nombre
system ("Pause"); //Permet au programme de rester à l'écran
return 0; //Tout fonctionne, on retourne à 0
}
I did what you say, now it's like this and it works :
1 2 3 4 5 6 7 8 9 10 11 12 13
iMax = iNb1;
if (iMax<iNb2)iMax=iNb2;
if (iMax<iNb3)iMax=iNb3;
if (iMax<iNb4)iMax=iNb4;
if (iMax<iNb5)iMax=iNb5;
cout << "Le plus grand nombre est : " << iMax << endl; //Afficher le plus petit nombre
iMin = iNb1,2,3,4,5;
if (iMin>iNb2)iMax=iNb2;
if (iMin>iNb3)iMax=iNb3;
if (iMin>iNb4)iMax=iNb4;
if (iMin>iNb5)iMax=iNb5;
cout << "Le plus petit nombre est : " << iMin << endl; //Afficher le plus petit nombre