Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
So my code looks like this:

void decimal_to_roman(int num);
{   

    printf("Enter a number: ");
    scanf("%d", &num);

    printf("Roman numerals: ");        

    while(num != 0)
    {

        if (num >= 1000)       // 1000 - m
        {
           printf("m");
           num -= 1000;
        }

        else if (num >= 900)   // 900 -  cm
        {
           printf("cm");
           num -= 900;
        }        

        else if (num >= 500)   // 500 - d
        {           
           printf("d");
           num -= 500;
        }

        else if (num >= 400)   // 400 -  cd
        {
           printf("cd");
           num -= 400;
        }

        else if (num >= 100)   // 100 - c
        {
           printf("c");
           num -= 100;                       
        }

        else if (num >= 90)    // 90 - xc
        {
           printf("xc");
           num -= 90;                                              
        }

        else if (num >= 50)    // 50 - l
        {
           printf("l");
           num -= 50;                                                                     
        }

        else if (num >= 40)    // 40 - xl
        {
           printf("xl");           
           num -= 40;
        }

        else if (num >= 10)    // 10 - x
        {
           printf("x");
           num -= 10;           
        }

        else if (num >= 9)     // 9 - ix
        {
           printf("ix");
           num -= 9;                         
        }

        else if (num >= 5)     // 5 - v
        {
           printf("v");
           num -= 5;                                     
        }

        else if (num >= 4)     // 4 - iv
        {
           printf("iv");
           num -= 4;                                                            
        }

        else if (num >= 1)     // 1 - i
        {
           printf("i");
           num -= 1;                                                                                   
        }

    }

    return 0;
}


Which I think would work, but when I try to compile it tells me
expected identifier or ‘(’ before ‘{’ token in the file
for the first line. Any help?

What I have tried:

I've tried editing it by changing the starting, but it just pops up different errors when I do
Posted
Updated 5-Oct-21 4:07am

This is supposed to be a function so the semi-colon at the end of the line should not be present.
C++
void decimal_to_roman(int num);
{

Correct code is:
C++
void decimal_to_roman(int num)  // <-- no semi-colon allowed here
{
 
Share this answer
 
Comments
Dave Kreskowiak 5-Oct-21 10:29am    
There has to be an entire class that's making this same mistake lately.
Richard MacCutchan 5-Oct-21 10:50am    
Probably all copying from the same place. :)
Try removing the semi colon at the end of the decimal_to_roman function.

void decimal_to_roman(int num);

Change as below

void decimal_to_roman(int num)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900