THIS IS HOMEWORK. thought i’d let you know. if you could point me in the direction that would help me discover why this error is happening, i’d appreciate it.
http://pastebin.com/hDUpfrsu is my current code (included below). why does it return ONE when i enter (in this order) 5, 6, 7 or other sequences?
#include <stdio.h>
#include <simpio.h>
#include <genlib.h>
/* finds the minimum among three integers using minimal amount of relational operations */
int main()
{
int myNumbers[2];
bool lowest;
printf("Enter the first integer...\t");
myNumbers[0] = GetInteger();
printf("Enter the second integer...\t");
myNumbers[1] = GetInteger();
printf("Enter the third integer...\t");
myNumbers[2] = GetInteger();
if (myNumbers[0] < myNumbers[1] && myNumbers[0] < myNumbers[2])
{
lowest = myNumbers[0];
}
if (myNumbers[0] > myNumbers[1] && myNumbers[1] < myNumbers[2])
{
lowest = myNumbers[1];
}
if (myNumbers[0] > myNumbers[2] && myNumbers[1] > myNumbers[2])
{
lowest = myNumbers[2];
}
printf("\n%d", lowest);
getchar();
return 0;
}
A few issues:
lowest is defined as a
bool, it should be anintwith how you are using itmyNumbers[2]is an array of size 2, it can only hold 2 numbers. Change the size declaration to 3.