I'm new to C++ and I'm trying to write a program that accepts a number between 1 and 5 and then displays the number in words (i.e., 1=one). This is an assignment and unfortunately there are parameters I have to go by. I would have used a switch statement and then returned the result to main(), but my instructions are to display the result within the function and use a series of if/else statements. Here's what I have so far:
Code:
#include <iostream>
using namespace std;
void numToWord(unsigned int); // function prototype
int main ()
{
unsigned int num;
cout << "Enter a number in the range 1-5: "; // requests a user-entered number
cin >> num;
void numToWord(unsigned int num); // function call
}
void numToWord(unsigned int num) // displays the entered number in words
{
if (num==1)
{
cout << "You entered the number one.";
}
else if (num==2)
{
cout << "You entered the number two.";
}
else if (num==3)
{
cout << "You entered the number three.";
}
else if (num==4)
{
cout << "You entered the number four.";
}
else if (num==5)
{
cout << "You entered the number five.";
}
else
cout << "You entered an invalid number.";
}
When I run it, it accepts the number but doesn't display any output.
If anyone can give me a tip, that would be great!