Ok, donc j'essaye d'écrire une main où il demandera à l'utilisateur d'entrer un nombre de 1 à 6 et si le nombre est de 6 il finira le programme. si elle est supérieure à 6, il vous sera demandé de ressaisir le numéro. La chose est, quand je l'exécute, il ne vérifie pas les déclarations "si" et va automatiquement à cette ligne "s'il vous plaît entrer une autre option"Confus au sujet de pourquoi cette principale ne fonctionne pas
des idées pourquoi mon programme ferait quelque chose comme ça? MISE À JOUR: Je dis qu'il ignore automatiquement toutes les instructions if
et pose la dernière question de la boucle while
.
int main()
{
int userChoice = 0;
print(); //printing all of the options.
cout << "Please enter one of the options listed below" <<endl;
cin >> userChoice;
while(userChoice != 6)// 6 = the user wishing the end the program when they press 6.
{
if(userChoice == 1) //adding integer to the front of the list
{
addValueFront();
}
else if(userChoice == 2)//adding integer to the back of the list
{
addValueBack();
}
else if(userChoice == 3)//removing from the list
{
int n = 0;
cout << "Please enter the integer you wish to remove" << endl;
cin >> n;
removeValue(n);
}
else if(userChoice == 4)//printing the list
{
printList();
}
else if(userChoice == 5)//printing the number of items from the list
{
printItem();
}
else
{
cout << "The number you have entered is too high. Please try again" << endl;
cin >> userChoice;
}
cout << "please enter another option" <<endl;
cin >> userChoice; //sets up which option the user can choose from.
}
}
Le titre n'est pas trop descriptif. – chris
Définir "ne fonctionne pas". Je parie que cela fonctionne et fait exactement ce que le code lui dit de faire. –
Voulez-vous dire 'while (userChoice! = 6)'? –