Thread: Starter C++ Program

  1. #1
    Registered User
    Join Date
    Feb 2018
    Posts
    19

    Starter C++ Program

    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!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    You never call the function in main(). Line 15 is a function prototype not a function call.

  3. #3
    Registered User
    Join Date
    Feb 2018
    Posts
    19
    I thought that line looked wrong. Thanks for the help, it runs perfectly now!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programming Starter Help
    By Zach_10 in forum C Programming
    Replies: 2
    Last Post: 12-09-2016, 04:01 AM
  2. Starter
    By SlashX1896 in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 09-14-2007, 11:30 AM
  3. Game creation starter.
    By DarkBrute in forum Game Programming
    Replies: 18
    Last Post: 01-28-2005, 09:46 PM
  4. Here's your starter for three...
    By SMurf in forum Windows Programming
    Replies: 1
    Last Post: 08-06-2003, 08:12 AM
  5. Game Starter?
    By CammoDude91 in forum C++ Programming
    Replies: 20
    Last Post: 07-27-2003, 02:24 PM

Tags for this Thread