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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education