Skip to content

Instantly share code, notes, and snippets.

@AmSmart
Created June 22, 2021 22:23
Show Gist options
  • Save AmSmart/bde3191ef3b22ef3f980cf66776faaa3 to your computer and use it in GitHub Desktop.
Save AmSmart/bde3191ef3b22ef3f980cf66776faaa3 to your computer and use it in GitHub Desktop.
EEE 376 Past Question Solutions
#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;
}
#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;
}
@OsabuohienAisosaJonathan

Sorry I would like to know if u tested this code before posting because I found some issues with the codes

@AmSmart
Copy link
Author

AmSmart commented Jun 23, 2021

Yep, I tested it with Dev C++ IDE to be precise. It runs well. What issues do you have?

@OsabuohienAisosaJonathan

I tested it on my phone "coding c" application, it ran into errors

@AmSmart
Copy link
Author

AmSmart commented Jun 27, 2021

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