it's a Roman numeral. Output the Arabic form. Treat "v" as 5 and "V" as 5000 (aka "v-bar"), etc. You must handle the subtractive rule. Perform basic

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 23PE
icon
Related questions
icon
Concept explainers
Question

use c program online compilation convert from roman numerals

 

Read a string from command line arg.

Assume it's a Roman numeral.

Output the Arabic form.

Treat "v" as 5 and "V" as 5000 (aka "v-bar"), etc.

You must handle the subtractive rule.

Perform basic error checking.

Desired: do conversion in a function.

ues a Replit URL

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 5 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

why is exit status 1?

main.c x +
C main.c> f main
1 #include <stdio.h>
#include <string.h>
23
2
3
4 int value(char r)
{
сл
6
7
8
9
10
11
12
13
if (r == 'I')
return 1;
if (r == 'V')
return 5;
'X')
}
if (r =
==
return 10;
if (r = == 'L')
return 50;
if (r == 'C')
14
15
16
17
18
19
20
21
22
23 int romanToInt(char *str)
return 100;
if (r == 'D')
Line 68: Col 2
return 500;
if (r == 'M')
return 1000;
return -1;
History
> Console x
> make -s
> ./main
Shell x
+
Usage: ./main <Roman Numeral>
exit status 1
>
O
:
B
Transcribed Image Text:main.c x + C main.c> f main 1 #include <stdio.h> #include <string.h> 23 2 3 4 int value(char r) { сл 6 7 8 9 10 11 12 13 if (r == 'I') return 1; if (r == 'V') return 5; 'X') } if (r = == return 10; if (r = == 'L') return 50; if (r == 'C') 14 15 16 17 18 19 20 21 22 23 int romanToInt(char *str) return 100; if (r == 'D') Line 68: Col 2 return 500; if (r == 'M') return 1000; return -1; History > Console x > make -s > ./main Shell x + Usage: ./main <Roman Numeral> exit status 1 > O : B
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

why show me 

make -s
 ./main
Usage: ./main <Roman Numeral>
exit status 1 in replit?

#include <stdio.h>
#include <string.h>

int value(char r)
{
    if (r == 'I')
        return 1;
    if (r == 'V')
        return 5;
    if (r == 'X')
        return 10;
    if (r == 'L')
        return 50;
    if (r == 'C')
        return 100;
    if (r == 'D')
        return 500;
    if (r == 'M')
        return 1000;
    return -1;
}

int romanToInt(char *str)
{
    int res = 0;

    for (int i = 0; i < strlen(str); i++)
    {
        int s1 = value(str[i]);

        if (i + 1 < strlen(str))
        {
            int s2 = value(str[i + 1]);

            if (s1 >= s2)
            {
                res=res+s1;
            }
            else
            {
                res=res+s2-s1;
                i++;
            }
        }
        else
        {
            res = res + s1;
            i++;
        }
    }

    return res;
}

int main(int argc, char *argv[])
{
    if (argc < 2)
    {
        printf("Usage: %s <Roman Numeral>\n", argv[0]);
        return 1;
    }

    char *str = argv[1];
    int result = romanToInt(str);
    printf("The Arabic numeral equivalent of %s is %d\n", str, result);

    return 0;
}

main.c x +
C main.c> f main
1 #include <stdio.h>
#include <string.h>
23
2
3
4 int value(char r)
{
сл
6
7
8
9
10
11
12
13
if (r == 'I')
return 1;
if (r == 'V')
return 5;
'X')
}
if (r =
==
return 10;
if (r = == 'L')
return 50;
if (r == 'C')
14
15
16
17
18
19
20
21
22
23 int romanToInt(char *str)
return 100;
if (r == 'D')
Line 68: Col 2
return 500;
if (r == 'M')
return 1000;
return -1;
History
> Console x
> make -s
> ./main
Shell x
+
Usage: ./main <Roman Numeral>
exit status 1
>
O
:
B
Transcribed Image Text:main.c x + C main.c> f main 1 #include <stdio.h> #include <string.h> 23 2 3 4 int value(char r) { сл 6 7 8 9 10 11 12 13 if (r == 'I') return 1; if (r == 'V') return 5; 'X') } if (r = == return 10; if (r = == 'L') return 50; if (r == 'C') 14 15 16 17 18 19 20 21 22 23 int romanToInt(char *str) return 100; if (r == 'D') Line 68: Col 2 return 500; if (r == 'M') return 1000; return -1; History > Console x > make -s > ./main Shell x + Usage: ./main <Roman Numeral> exit status 1 > O : B
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

why after run have a lot error?

C main.c x +
C main.c> f main
123
#include <stdio.h>
#include <string.h>
Int value(char r)
{
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 Int romanToInt(char *str)
24
{
25
26
27
Line 68: Col 2
}
'I').
Return 1;
If (r 'V')
Return 5;
If (r 'X')
Return 10;
(L').
Return 50;
'C')
Return 100;
If (r
If (r
If (r
==
==
If (r 'D')
Return 500;
If (r 'M')
Return 1000;
Return -1;
Int res =
0;
For (int I = 0; I < strlen(str); i++)
|||
History
:
Shell x +
./main.c:10:14: error: non-ASCII characters are not allower
side of literals and identifiers
If (r 'X')
> Console x
./main.c:10:18: error: non-ASCII characters are not allowed out
side of literals and identifiers
If (r
'X')
==
./main.c:10:22: error: expected ';' after expression
If (r
'X')
./main.c:10:17: error: use of undeclared identifier 'X'
If (r 'X')
./main.c:11:9: error: use of undeclared identifier 'Return'
Return 10;
:
./main.c:12:14: error: non-ASCII characters are not allowed out
side of literals and identifiers
If (r = 'L')
==
./main.c:12:18: error: non-ASCII characters are not allowed out
side of literals and identifiers
If (r 'L')
./main.c:12:22: error: expected ';' after expression
If (r
'L')
fatal error: too many errors emitted, stopping now [-ferror-lim
it=]
20 errors generated.
make: *** [Makefile:10: main] Error 1
exit status 2
>
Transcribed Image Text:C main.c x + C main.c> f main 123 #include <stdio.h> #include <string.h> Int value(char r) { 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Int romanToInt(char *str) 24 { 25 26 27 Line 68: Col 2 } 'I'). Return 1; If (r 'V') Return 5; If (r 'X') Return 10; (L'). Return 50; 'C') Return 100; If (r If (r If (r == == If (r 'D') Return 500; If (r 'M') Return 1000; Return -1; Int res = 0; For (int I = 0; I < strlen(str); i++) ||| History : Shell x + ./main.c:10:14: error: non-ASCII characters are not allower side of literals and identifiers If (r 'X') > Console x ./main.c:10:18: error: non-ASCII characters are not allowed out side of literals and identifiers If (r 'X') == ./main.c:10:22: error: expected ';' after expression If (r 'X') ./main.c:10:17: error: use of undeclared identifier 'X' If (r 'X') ./main.c:11:9: error: use of undeclared identifier 'Return' Return 10; : ./main.c:12:14: error: non-ASCII characters are not allowed out side of literals and identifiers If (r = 'L') == ./main.c:12:18: error: non-ASCII characters are not allowed out side of literals and identifiers If (r 'L') ./main.c:12:22: error: expected ';' after expression If (r 'L') fatal error: too many errors emitted, stopping now [-ferror-lim it=] 20 errors generated. make: *** [Makefile:10: main] Error 1 exit status 2 >
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr