Commit a34fa21a authored by Kevin Lyda's avatar Kevin Lyda 💬

Initial version w/o timing or counters.

parents
cube-test
.*.swp
#
# Makefile
# Kevin Lyda, 2017-10-12 19:14
#
cube-test: cube-test.c
cc -Wall -o cube-test cube-test.c
# vim:ft=make
#
/*
* cube-test.c
* Copyright (C) 2017 Kevin Lyda <kevin@phrye.com>
*
* Distributed under terms of the GPL license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int
random_two_digit_number() {
return (rand() % 90) + 10;
}
int
cube(int n) {
return n * n * n;
}
int
read_number() {
char buf[10];
if (!fgets(buf, sizeof buf, stdin)) {
return 0;
}
return atoi(buf);
}
int
main(int argc, char *argv[]) {
int guess, number;
srand(time(NULL));
while (1) {
number = random_two_digit_number();
printf("Number is %d. Cube root (0 to exit)? ", cube(number));
guess = read_number();
if (guess == 0) {
exit(0);
}
if (guess == number) {
printf("Correct.\n");
} else {
printf("Not correct. Number was %d.\n", number);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment