in every single looping state so that I can understand all of them well. Have fully completed it with the do{}while loop. The for loop is giving me trouble though, this is what I have so far -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int main()
{
for(int x=0; x!=5;) {
cout<<"Enter any number other than 5: ";
cin>>x;
cin.ignore();
if (x==5) {
cout<<"You werent supposed to enter 5...";
}
}
cin.get();
}
The first part of the challenge works fine. To do the first star however I would need another variable to count how many times I press enter and the loop structure doesn't allow me to use more than one variable. Any ideas?
http://cplusplus.com/forum/articles/12974/ - While( user == gullible ) - I am trying to do the 1st star of the problem. well hmmm if you say i can use more than one variable in it then i will continue experimenting.
EDIT: ah... so you can declare the variables outside of the for loop. okay I will try that
lol it worked like a charm. Thanks...it was the tutorial i read that caused the confusion...http://www.cprogramming.com/tutorial/lesson3.html, it exemplifies placing the variables inside the for loop and i thought I must do it like that. Sorry for the simple question.
#include <iostream>
usingnamespace std;
int main()
{
int x;
int j;
for(x=0; x!=5; j=1; j<=10) {
cout<<"Enter any number other than 5: ";
cin>>x;
cin.ignore();
if (x==5) {
cout<<"You werent supposed to enter 5...";
}
j++;
}
cin.get();
}