This question already has an answer here:
forgive me for any shortcomings in my descriptionof my problem but its my first day here. so my program wont compile. it keeps kicking out "undefined reference to 'isOdd' and 'IsEven', also an ld returned 1 exit status. cant seem to figure out whats causing the error. its a random number generator trying to use bool to judge whether a set of random integers are both even or if one of them is odd.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
bool isOdd (int num1, int num2);
bool isEven (int num1, int num2);
void valueForOdd (int num1, int num2);
void valueForBothEven (int num1, int num2);
int i;
int num1;
int num2;
int main(void)
{
srand(time(NULL));
for (i=1; i <= 10; ++i) {
num1 = rand() % 10 + 1;
num2 = rand() % 10 + 1;
printf("The two random numbers are %u and %u\n", num1, num2);
}
bool valueForOdd = isOdd (num1, num2);
if (valueForOdd) {
printf("one of these numbers, %u and %u, isOdd.\n\n", num1, num2);
}
else {
printf("\n");
}
bool isOdd (int num1, int num2)
{
if ((num1 % 2 != 0) || (num2 % 2 != 0)) {
return true;
}
else {
return false;
}
}
bool valueForBothEven = isEven (num1, num2);
if (valueForBothEven) {
printf("Both of these numbers, %u and %u, are even.\n\n", num1, num2);
}
else {
printf("\n");
}
bool isEven (int num1, int num2)
{
if ((num1 % 2 == 0) && (num2 % 2 == 0)) {
return true;
}
else {
return false;
}
}
}
Aucun commentaire:
Enregistrer un commentaire