#include <stdio.h>
main () {
int x, r, attempts;
char c, c2;
x = 10;
printf("\nHello, World! %d \n", x);
printf("Did it work? (y/n)\n");
c = getchar();
putchar(c);
while (c!= 'n' && c!= 'y' && c!= 'n' && c!= 'N' && c!= 'Y') {
printf("\nYou entered an invalid character, try again\n");
c = getchar();
}
if (c== 'n' || c== 'N') {
printf("\nThat sucks!");
r = 0;
}
if (c == 'y' || c == 'Y') {
printf("\nRock on!");
r = 1;
}
while (r == 0) {
printf("\nUghh, I (or you for that matter), failed. Try again (y/n)?\n");
c2 = getchar();
putchar(c2);
if (c2== 'n' || c2== 'N') {
printf("\nThat's too bad!\n");
}
if (c2== 'y' || c2== 'Y') {
printf("\nOk, I'll run main again!\n");
++attempts;
r = 1;
main ();
}
}
printf("\nThe total number of attempts necessary where %d\n", attempts);
return (attempts);
}
Issues: ?? I don't know exactly what's wrong (or I wouldn't be asking ;) ), but here is sample output:Quote
Hello, World! 10
Did it work? (y/n)
n
That sucks!
Ughh, I (or you for that matter), failed. Try again (y/n)?
Ughh, I (or you for that matter), failed. Try again (y/n)?
y
Ok, I'll run main again!
Hello, World! 10
Did it work? (y/n)
You entered an invalid character, try again
y
Rock on!
The total number of attempts necessary where 121
The total number of attempts necessary where 122
Did it work? (y/n)
n
That sucks!
Ughh, I (or you for that matter), failed. Try again (y/n)?
Ughh, I (or you for that matter), failed. Try again (y/n)?
y
Ok, I'll run main again!
Hello, World! 10
Did it work? (y/n)
You entered an invalid character, try again
y
Rock on!
The total number of attempts necessary where 121
The total number of attempts necessary where 122


Sign In
Create Account

Back to top









