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 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);...

  • Please help run all the examples correctly and only the examples without extra things in or...

    Please help run all the examples correctly and only the examples without extra things in or less things in, it should run EXACTLY 100% like the examples. C language ONLY. And please dont reply if you cant run all the examples given. We know the tr command allows you to replace or translate characters in of a stream. It takes in two arguments - a set of characters to be replaced and a set of replacement characters. The full functionality...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • please help me fix this. I'm getting it all mixed up in user defined functions. here's...

    please help me fix this. I'm getting it all mixed up in user defined functions. here's the question. This week we'll write a C program that lets the user play the game of Rock, Paper, Scissors against the computer. Your program will call a user-defined function named display_rules that displays the rules of the game. It then proceeds to play the game. To determine the winner, your program will call another user- defined function called determine_winner that takes two integer...

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
ADVERTISEMENT