Public feed #376525

Something

public text v1 · immutable
Raw Edit
·published 2007-03-01 02:33 UTC
rendered paste body
#include <iostream>

using namespace std;

//prototypes
bool isInRange(int anInt);
int cutOddTails(int anInt);
bool isVowel(char aChar);
int lastOddInArray(int anArray[], int size);
void teachYouEnglish(int anInt);

int main()
{
	//Part a being called. (include display portions)
	bool result = isInRange(500);
	if (result == true)
	{
	cout << "The variable is within range" << endl;
	}
	else
	{
		cout << "The variable is NOT within range" << endl;
	}

	//Part B
    int intResult = cutOddTails(21);
	cout << "The result is: " << intResult << endl;

	//PartC

	result = isVowel('A');

	if (result == true)
	{
	cout << "The char is a vowel" << endl;
	}
	else
	{
		cout << "The variable is NOT a vowel" << endl;
	}

	//part D
	const int ARRAYSIZE = 10;
	int theArray[ARRAYSIZE] = {1,2,3,4,5,6,7,8,9,10};
	intResult = lastOddInArray(theArray, ARRAYSIZE);
    cout << "The last odd value is: "<< intResult << endl;

	//part E
	teachYouEnglish(1); // will just display output

	



return 0;

}

//checks if a number is in the range specified - PART A
bool isInRange(int anInt)
{
const int UPPER_LIMIT = 100;
const int LOWER_LIMIT = 0;

if ((anInt > LOWER_LIMIT) && (anInt < UPPER_LIMIT))
{
	return true;
}
else
{
	return false;
}

}

//checks if an interger is odd.  If so, it cuts the last digit. -- PART B
// divide by 10 to cut a digit....

int cutOddTails(int anInt)
{
if (anInt % 2 != 0)
{
anInt = anInt/10; // strips a digit
}
return anInt;
}

//checks if an int is a vowel or not
bool isVowel(char aChar)
{
aChar = tolower(aChar); // converts to lower case to make it quicker

if (aChar == 'a' || aChar == 'e' || aChar == 'i' || aChar == 'o' || aChar == 'u' || aChar == 'y')
{
	return true;
}
else
{
	return false;
}

}

//returns the last odd value in the array
int lastOddInArray(int anArray[], int size)
{
int lastOdd = 0;

for (int i = 0; i < size; i++)
{
	if ((anArray[i] % 2) != 0)
	{
	lastOdd = anArray[i];
	}
}
return lastOdd;

}

//displays a sequence based on int
void teachYouEnglish(int anInt)
{
switch (anInt)
{
case 1:
	cout << "1st" << endl;
	break;
case 2:
	cout << "2nd" << endl;
	break;
case 3:
	cout << "3rd" << endl;
	break;
case 4:
	cout << "4th" << endl;
	break;
}

}