Created
June 22, 2021 22:23
-
-
Save AmSmart/bde3191ef3b22ef3f980cf66776faaa3 to your computer and use it in GitHub Desktop.
EEE 376 Past Question Solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
int getRandomNumber(); | |
int main(){ | |
int guess = 0; | |
char playAgain = 'y'; | |
bool wrongGuess; | |
while(playAgain == 'y'){ | |
int random = getRandomNumber(); | |
wrongGuess = false; | |
printf("I have you a number between 1 and 1000\n"); | |
printf("Can you guess my number?\n"); | |
printf("Please type your first guess\n"); | |
while(!wrongGuess){ | |
scanf("%d", &guess); | |
if(guess == random){ | |
wrongGuess = true; | |
printf("Excellent! You guessed the number! Would you like to play again(y or n)\n"); | |
scanf(" %c", &playAgain); | |
} | |
else if(guess > random){ | |
printf("Too high. Try again %d %d\n", guess, random); | |
} | |
else{ | |
printf("Too low. Try again %d %d\n", guess, random); | |
} | |
} | |
} | |
return 0; | |
} | |
int getRandomNumber(){ | |
int num = (rand() % 1000) + 1; | |
printf("Random Number is %d\n", num); | |
return num; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
int a = 0, b = 0, result = 0, answer = 0; | |
int main(){ | |
while(true){ | |
generateQuestion(); | |
printf("What is the answer to %d times %d?\n", a, b); | |
scanf("%d", &answer); | |
while(answer != result){ | |
printf("Not Correct! Please try again!\n"); | |
scanf("%d", &answer); | |
} | |
printf("Very good! Try the next one\n"); | |
} | |
return 0; | |
} | |
void generateQuestion(){ | |
a = rand() % 10; | |
b = rand() % 10; | |
result = a * b; | |
} |
I tested it on my phone "coding c" application, it ran into errors
That's a limited development environment. It might be the cause of the errors. You can share your errors here anyway and I'll see if I can offer any help.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep, I tested it with Dev C++ IDE to be precise. It runs well. What issues do you have?