Beginner excerise while( user==guillible)

I'm doing the while (user== gullible) first star exercise on this page http://www.cplusplus.com/forum/articles/12974/
My laptop is still getting fixed and my friend won't let me install code::blocks on his computer. So I can't check to see if the code I wrote works. So I was wondering if any one here could tell me if my code would work and what I could do to make it better.

#include <iostream>
using namespace std;

int main ()
{
int num;
int iteration=0;
do {
cout<<"Enter any number other than 5"<<endl;
cin>>num;
if (num == 5) {cout<<"Hey! you weren't suppose to enter 5";}
iteration++;}
while (num != 5 && iteration != 10);

if (iteration == 10) {cout<<"Wow, you're more patient than I am, you win.";}
return 0;
}
Last edited on
At the first glance it seems that the code is valid.
http://ideone.com/

Sometimes you can put your code on there. It won't replace an installed compiler, though.
Your friend doesn't seem to trust you very much. Either that, or doesn't know how to uninstall software.
Thanks for the help. I use ideone.com and the code work.
Hello, I'm doing the same exercise, but I'm writing it in C. Now I've got the program to run how it is
supposed to, although I'm having a hard time getting it to loop through 10 times. The code I have so far is:

#include <stdio.h>
int main(void)

{

int input;

printf("\nPatient's Program...\n");
printf("Enter Any Number EXECPT 5...\n");
printf("Number: ");
scanf("%d", &input);

switch (input) {
case 5:

printf("\nYou Was Not Supposed To Press That \n\n");
{break;}

default:
while(input != 5) /* The Loop starts here, */
{
printf("Again:");
scanf("%d", &input);
}
if (input == 5 )
{
printf("\nYou Was Not Supposed To Press That!. \n\n");
}

}

getchar();
return 0;
}

I guess the question is, I need it to loop through 10 times, until the certain number is typed, what code do I need to break the 'while' statement, and print the output, on the tenth input?

Thanks In Advance.
Last edited on
I guess the question is, I need it to loop through 10 times, until the certain number is typed, what code do I need to break the 'while' statement, and print the output, on the tenth input?


1
2
3
4
5
int count = 10;

while (input != 5 && count-- != 0)
{
}


Also, please put your code inside code tags. Look to the right for the <> button.
Thank you, And in future I will use the Code Tags.
Topic archived. No new replies allowed.