Question

I'm having trouble getting a certain output with my program Here's my output: Please input a...

I'm having trouble getting a certain output with my program

Here's my output:

Please input a value in Roman numeral or EXIT or quit: MM

MM = 2000

Please input a value in Roman numeral or EXIT or quit: mxvi

Illegal Characters.

Please input a value in Roman numeral or EXIT or quit: MXVI

MXVI = 969

Please input a value in Roman numeral or EXIT or quit: EXIT

Illegal Characters.

Here's my desired output:

Please input a value in Roman numerals or EXIT to quit: MM

MM = 2000

Please input a value in Roman numerals or EXIT to quit: MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM

Error too many characters! Must be less than 21 characters.

Please input a value in Roman numerals or EXIT to quit: XYZ

Illegal Characters.

Please input a value in Roman numerals or EXIT to quit: MXVI

MXVI = 1016

Please input a value in Roman numerals or EXIT to quit: EXIT

Thank you for using the Roman Numeral to Decimal calculator.

Goodbye!

Here's my code:

#include<stdio.h>

#include <stdlib.h>

#include <stdbool.h>

#include<string.h>

bool Prompt(char romanNumeral[], int maxSize);

bool ProperRoman (const char romanNumeral[]);

void NumeralToDecimal (char romanNumeral[], int decimalValues[]);

int CalculateDecimalValue (int decimalValues[], int numDigits);

int main(){

int a[20];

int deciVal[20];

char romanNum[20];

int i = 0;

while(1){

printf("Please input a value in Roman numeral or EXIT or quit: ");

scanf("%s",&romanNum[i]);

if(ProperRoman(romanNum)){

if(Prompt(romanNum,20))

NumeralToDecimal(romanNum,deciVal);

}

if(strcmp(romanNum,"EXIT")==0)

printf("Thank you for using the Roman Numeral to Decimal calculator.");

printf("Goodbye!")

break;

}

}

bool Prompt(char romanNumeral[], int maxSize){

if(strlen(romanNumeral)>maxSize)

{

printf("Error too many characters! Must be less than 21 characters.\n");

return false;

}

return true;

}

void NumeralToDecimal (char romanNumeral[], int decimalValues[]){

int numDigits = strlen(romanNumeral);

int i;

for(i = 0; i < numDigits;i++){

if (romanNumeral[i]=='M'){

decimalValues[i] = 1000;

}else if (romanNumeral[i]=='D'){

decimalValues[i] = 500;

}else if (romanNumeral[i]=='C'){

decimalValues[i] = 100;

}else if (romanNumeral[i]=='L'){

decimalValues[i] = 50;

}else if (romanNumeral[i]=='X'){

decimalValues[i] = 10;

}else if (romanNumeral[i]=='V'){

decimalValues[i] = 5;

}else if (romanNumeral[i]=='I'){

decimalValues[i] = 1;

}

}

printf("%s = %d\n",romanNumeral,CalculateDecimalValue (decimalValues,numDigits));

}

bool ProperRoman (const char *romanNumeral){

int i;

int flag = 1;

for(i = 0; i < strlen(romanNumeral);i++){

if((romanNumeral[i]=='I')|| (romanNumeral[i]=='V')|| (romanNumeral[i]=='X')||

(romanNumeral[i]=='L')||(romanNumeral[i]=='C')||

(romanNumeral[i]=='D')||(romanNumeral[i]=='M'))

romanNumeral++;

else{

printf("Illegal Characters.\n");

flag = 0;

break;

}

}

return flag;

}

int CalculateDecimalValue (int decimalValues[], int numDigits){

int maxsize = numDigits;

int result = 0;

int i;

int lastValue;

for(i=0; i < maxsize; i++){

if (decimalValues[i] > lastValue) {

result += (decimalValues[i] - 2*lastValue);

}

else {

result += decimalValues[i];

}

lastValue = decimalValues[i];

}

return result;

}


0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include<stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include<string.h>
#include<limits.h>
bool Prompt(char romanNumeral[], int maxSize);
bool ProperRoman (const char romanNumeral[]);
void NumeralToDecimal (char romanNumeral[], int decimalValues[]);
int CalculateDecimalValue (int decimalValues[], int numDigits);

void main(){
int a[20];
int deciVal[20];
char romanNum[20];
int i = 0;
while(1){
printf("Please input a value in Roman numeral or EXIT or quit: ");
scanf("%s",&romanNum);
if(strcmp(romanNum,"EXIT")==0)
{
printf("Thank you for using the Roman Numeral to Decimal calculator.\nGoodbye!\n");

break;
}
if(ProperRoman(romanNum)){
if(Prompt(romanNum,20))
NumeralToDecimal(romanNum,deciVal);
}

}
}

bool Prompt(char romanNumeral[], int maxSize){
if(strlen(romanNumeral)>maxSize)
{
printf("Error too many characters! Must be less than 21 characters.\n");
return false;
}
return true;
}


void NumeralToDecimal (char romanNumeral[], int decimalValues[]){
int numDigits = strlen(romanNumeral);
int i;
for(i = 0; i < numDigits;i++){
if (romanNumeral[i]=='M'){
decimalValues[i] = 1000;
}else if (romanNumeral[i]=='D'){
decimalValues[i] = 500;
}else if (romanNumeral[i]=='C'){
decimalValues[i] = 100;
}else if (romanNumeral[i]=='L'){
decimalValues[i] = 50;
}else if (romanNumeral[i]=='X'){
decimalValues[i] = 10;
}else if (romanNumeral[i]=='V'){
decimalValues[i] = 5;
}else if (romanNumeral[i]=='I'){
decimalValues[i] = 1;
}
}
printf("%s = %d\n",romanNumeral,CalculateDecimalValue (decimalValues,numDigits));
}

bool ProperRoman (const char *romanNumeral){
int i;
int flag = 1;
for(i = 0; i < strlen(romanNumeral);i++){
if((romanNumeral[i]=='I')|| (romanNumeral[i]=='V')|| (romanNumeral[i]=='X')||
(romanNumeral[i]=='L')||(romanNumeral[i]=='C')||
(romanNumeral[i]=='D')||(romanNumeral[i]=='M'))
continue;
else{
printf("Illegal Characters.\n");
flag = 0;
break;
}
}
return flag;
}

int CalculateDecimalValue (int decimalValues[], int numDigits){
int maxsize = numDigits;
int result = 0;
int i;
int lastValue = INT_MAX;
for(i=0; i < maxsize; i++){
if (decimalValues[i] > lastValue) {
// We've seen something like "IX" or "XC".
// Need to undo the addition of the last value,
// and then add (value - lastValue).
result += (decimalValues[i] - 2 * lastValue);
}
else {
result += decimalValues[i];
}
lastValue = decimalValues[i];
}
return result;

}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
I'm having trouble getting a certain output with my program Here's my output: Please input a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm having trouble getting my program to output this statement Enter a sentence: Test! There are...

    I'm having trouble getting my program to output this statement Enter a sentence: Test! There are 5 total characters. There are 1 vowel. There are 1 UPPERCASE letters. There are 3 lowercase letters. There are 1 other characters. Here's my code: #include<string.h> #include<stdio.h> #include<stdbool.h> int main() { char str[100]; int i; int vowels=0; int UC; int LC; int Others; int c; printf("Enter a sentence: \n"); gets(s); LC=countLC(&s); UC=countUC(&s); Others=countOthers(&s); printf("There are %d total characters.\n", ; for(i=0; i<strlen(str); i++){ if(isVowel(str[i])) vowels++;...

  • I'm having trouble getting my program to output What is your first name? damion what is...

    I'm having trouble getting my program to output What is your first name? damion what is your last name? anderson damion, Your first name is 6 characters Your last name, anderson, is 8 characters Your name in reverse is: noimad nosredna This is my code so far: #include <stdlib.h> #include <stdio.h> void sizeOfName(char** name); void printSizeOfName(int *first, int *last, char** name); void reverseString(int *first, int *last, char** name); int main() {   char** name;   name = (char**)malloc(2*sizeof(char*));   name[0] = (char*)malloc(100*sizeof(char));   name[1]...

  • i'm trouble getting my program to print this output and repeat until asked to quit the...

    i'm trouble getting my program to print this output and repeat until asked to quit the program Enter a telephone number using letterss (EXIT to quit): GET LOAN The corresponding telephone number is: 438-5626 Here's my code: #include <stdio.h> #include <string.h> char getNumber(char aC) { char c = ' '; switch (aC) { case 'A': case 'B': case 'C': c = '2'; break; case 'D': case 'E': case 'F': c = '3'; break; case 'G': case 'H': case 'I': c...

  • Which part of this program is used for input one context free grammar? And if you...

    Which part of this program is used for input one context free grammar? And if you want to give another different context free grammar, how to do that? code: #include<stdio.h> #include<stdlib.h> #include<string.h> #define MaxVtNum 20 #define MaxVnNum 20 #define MaxPLength 20 #define MaxSTLength 50 char stack[20]={'#','E'}; char input[MaxSTLength]; char termin[MaxVtNum]={'i','+','*','(',')','#'}; char non_termin[MaxVnNum]={'E','G','T','H','F'}; struct product{ char left; char right[MaxPLength]; int length; }; struct product E,T,G,G1,H,H1,F,F1; struct product M[MaxVnNum][MaxVtNum]; int flag=1; int top=1; int l; void print_stack(){ } } } } }...

  • I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle):...

    I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle): L Enter an integer length between 1 and 25: 13 ************* Which shape (L-line, T-triangle, R-rectangle): t Enter an integer base length between 3 and 25: 5 * ** *** **** ***** Which shape (L-line, T-triangle, R-rectangle): r Enter an integer width and height between 2 and 25: 4 5 **** **** **** **** **** Here's my code: #include <stdio.h> #include <ctype.h> const int...

  • I'm having trouble rounding the numbers i'm getting in my output here's my code: #include<stdio.h> int...

    I'm having trouble rounding the numbers i'm getting in my output here's my code: #include<stdio.h> int main() { char gender; float a1, a2, a3, a4, a5; float waistmeasurement, wristmeasurement, hipmeasurement, forarmmeasurement; float B, bodyweight, Bodyfat, Bodyfatpercentage;    printf("This program determines the body fat of a person.Enter your gender (f|F|m|M): "); scanf("%c", &gender); printf("\n");    if(gender=='F' || gender=='f'){ printf("Enter body weight (in pounds): \n"); scanf("%f", &bodyweight); printf("Enter wrist measurement at fullest point (in inches): \n"); scanf("%f", &wristmeasurement); printf("Enter waist measurement at...

  • i'm having trouble making an else statement that will allow the program to add and output...

    i'm having trouble making an else statement that will allow the program to add and output the average the valid numbers inputed into the program. Here's my output: Enter Score 1:36 Enter Score 2:-1 Invalid Input Enter Score 2:89.5 Enter Score 3:42 Enter Score 4:66.3 Enter Score 5:93 You entered: 36.000000, 89.500000, 42.000000, 66.300000, 93.000000 Total Score: 362.800000 Average Score: 72.560000 Max Score: 93.000000 Min Score: 36.000000 Here's my code: #include <stdio.h> int main(void) { double score[5]; double min; double...

  • Please help modify my C program to be able to answer these questions, it seems the...

    Please help modify my C program to be able to answer these questions, it seems the spacing and some functions arn't working as planeed. Please do NOT copy and paste other work as the answer, I need my source code to be modified. Source code: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { char title[50]; char col1[50]; char col2[50]; int point[50]; char names[50][50]; printf("Enter a title for the data:\n"); fgets (title, 50, stdin); printf("You entered: %s\n", title);...

  • Hello, can someone please fix my code? It runs perfect but I'm having trouble with the...

    Hello, can someone please fix my code? It runs perfect but I'm having trouble with the index for the incorrect answer array; please run some tests to ensure the code runs properly, thank you! Here is the code: ___________________________________________________________________________________________________________________________ import java.util.Scanner; public class DriverTest{    final static int QuestionTotal = 10;    public static void main(String[] args){          // scanner and answer key        Scanner scan = new Scanner(System.in);        final char[] answers = {'A', 'B', 'C',...

  • ANSWER ASAP PLEASE Using only the standard input/output function fgetc(), define a C function, called int...

    ANSWER ASAP PLEASE Using only the standard input/output function fgetc(), define a C function, called int readInt(int *value), that reads an integer from the keyboard (stdin), stores it in *value and, returns 1 for success or 0 for fail (in case the user enters nondigit characters). In particular, readInt() reads all characters, one by one, until a blank (or newline) is encountered. The string is then converted to an integer. It is also possible to have the sign charcater (+/-)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT