I have to ask the user to choose the initial value, the finale value and the incrementation in a for loop. My problem is that the c variable doesn't seem to be going up according to the i variable.
Everytime I try to run the program it only displays c=d when I cout << c; If I take out the break; it just displays c with the value d an infinite amount of time. Here's what I wrote:
int d, f, i, c;
cout << "Quelle est la valeur de depart?\n";//whats the initial value
cin >> d;
cout << "Quelle est la valeur de fin?\n";//whats the final value
cin >> f;
cout << "Quel est l'incrementation?\n";//increment?
cin >> i;
if (f > d)
{
for (c=d; c <= f; c=c+i)
{
cout << c << endl;
break;
}//for
}//if+
else if (f < d)
{
for (c=d; c >= f; c=c-i)
{
cout << c << endl;
break;
}//for
}//else if-
else
{
c = d;
cout << c << endl;
}//else
system("pause");
return 0;
Thank you.
Aucun commentaire:
Enregistrer un commentaire