HELP for my Pascal Assignment Please

Hi
I want help to solve this problem in pascal:

In this problem you will design and implement a Roman numeral calculator. Most people are unaware that the subtractive Roman numeral notation commonly in use today (such as IV Meaning 4) was only rarely used during the time of the Roman Republic and Empire. For ease of calculation, the Romans most frequently used a purely additive notation in which a number was simply the sum of its digits (4 equals IIII in this notation).
Each number starts with the digit of highest value and ends with the one of smallest value. This is the notation we will use in this problem.

Your program will input two Roman numbers and an arithmetic operator and print out the result of the operation, also as a Roman number. The values of the Roman digits are as follows:

I 1
V 5
X 10
L 50
C 100
D 500
M 1000

Thus, the number MDCCCCLXXXVIIII represents 1989. The arithmetic operators that your program should recognize in the input are +, -, * and /. These should perform the Pascal operations of integer addition, subtraction, multiplication and division.

One way of approaching this problem is to convert the Roman numbers into integers, perform the required operation, and then convert the result back into Roman number for printing. The following might be a sample run of the program, for an interactive system.

Enter the first number:
MCCXXVI
The first number is 1226
Enter the second number:
LXVIIII
The second number is 69
Enter the desired arithmetic operation:
+
The sum of MCCXXVI and LXVIIII is MCCLXXXXV (1295)

Your program should use a good style, appropriate comments, meaningful identifiers, proper indentation and avoid side effects.

It should also check for errors in the input, such as illegal digits or arithmetic operators and take appropriate actions when these are found. You may also have the program check to be sure that the numbers are in purely additive forms digits are followed only by digits of the same or lower value.

And I have to do the problem with just this sections:Choice Statements, Loop Statements, Procedures and Functions,Subrange,Arrays,Enumarated types,TextFiles and Records.

Comments

  • : Hi
    : I want help to solve this problem in pascal:
    :
    : In this problem you will design and implement a Roman numeral calculator. Most people are unaware that the subtractive Roman numeral notation commonly in use today (such as IV Meaning 4) was only rarely used during the time of the Roman Republic and Empire. For ease of calculation, the Romans most frequently used a purely additive notation in which a number was simply the sum of its digits (4 equals IIII in this notation).
    : Each number starts with the digit of highest value and ends with the one of smallest value. This is the notation we will use in this problem.
    :
    : Your program will input two Roman numbers and an arithmetic operator and print out the result of the operation, also as a Roman number. The values of the Roman digits are as follows:
    :
    : I 1
    : V 5
    : X 10
    : L 50
    : C 100
    : D 500
    : M 1000
    :
    : Thus, the number MDCCCCLXXXVIIII represents 1989. The arithmetic operators that your program should recognize in the input are +, -, * and /. These should perform the Pascal operations of integer addition, subtraction, multiplication and division.
    :
    : One way of approaching this problem is to convert the Roman numbers into integers, perform the required operation, and then convert the result back into Roman number for printing. The following might be a sample run of the program, for an interactive system.
    :
    : Enter the first number:
    : MCCXXVI
    : The first number is 1226
    : Enter the second number:
    : LXVIIII
    : The second number is 69
    : Enter the desired arithmetic operation:
    : +
    : The sum of MCCXXVI and LXVIIII is MCCLXXXXV (1295)
    :
    : Your program should use a good style, appropriate comments, meaningful identifiers, proper indentation and avoid side effects.
    :
    : It should also check for errors in the input, such as illegal digits or arithmetic operators and take appropriate actions when these are found. You may also have the program check to be sure that the numbers are in purely additive forms – digits are followed only by digits of the same or lower value.
    :
    : And I have to do the problem with just this sections:Choice Statements, Loop Statements, Procedures and Functions,Subrange,Arrays,Enumarated types,TextFiles and Records.
    :
    :
    The way it works is: you try to write some code and then post it back when you run into trouble. Someone might help you then. Simply copy/pasting from your syllabus into a message like this won't cut it.
  • : : Hi
    : : I want help to solve this problem in pascal:
    : :
    : : In this problem you will design and implement a Roman numeral calculator. Most people are unaware that the subtractive Roman numeral notation commonly in use today (such as IV Meaning 4) was only rarely used during the time of the Roman Republic and Empire. For ease of calculation, the Romans most frequently used a purely additive notation in which a number was simply the sum of its digits (4 equals IIII in this notation).
    : : Each number starts with the digit of highest value and ends with the one of smallest value. This is the notation we will use in this problem.
    : :
    : : Your program will input two Roman numbers and an arithmetic operator and print out the result of the operation, also as a Roman number. The values of the Roman digits are as follows:
    : :
    : : I 1
    : : V 5
    : : X 10
    : : L 50
    : : C 100
    : : D 500
    : : M 1000
    : :
    : : Thus, the number MDCCCCLXXXVIIII represents 1989. The arithmetic operators that your program should recognize in the input are +, -, * and /. These should perform the Pascal operations of integer addition, subtraction, multiplication and division.
    : :
    : : One way of approaching this problem is to convert the Roman numbers into integers, perform the required operation, and then convert the result back into Roman number for printing. The following might be a sample run of the program, for an interactive system.
    : :
    : : Enter the first number:
    : : MCCXXVI
    : : The first number is 1226
    : : Enter the second number:
    : : LXVIIII
    : : The second number is 69
    : : Enter the desired arithmetic operation:
    : : +
    : : The sum of MCCXXVI and LXVIIII is MCCLXXXXV (1295)
    : :
    : : Your program should use a good style, appropriate comments, meaningful identifiers, proper indentation and avoid side effects.
    : :
    : : It should also check for errors in the input, such as illegal digits or arithmetic operators and take appropriate actions when these are found. You may also have the program check to be sure that the numbers are in purely additive forms – digits are followed only by digits of the same or lower value.
    : :
    : : And I have to do the problem with just this sections:Choice Statements, Loop Statements, Procedures and Functions,Subrange,Arrays,Enumarated types,TextFiles and Records.
    : :
    : :
    : The way it works is: you try to write some code and then post it back when you run into trouble. Someone might help you then. Simply copy/pasting from your syllabus into a message like this won't cut it.
    :
    One Example That I did Is like that but doesn't work(It Gives Type Mismatch):
    PROGRAM Roman_Calculator;
    TYPE
    indexType = 1..7;
    RomanNumberArray = array [indexType] of char;
    RomansNumbers = (I,V,X,L,C,D,M);

    VAR
    RomansNu : RomansNumbers;
    RomansNo : RomanNumberArray;
    first,second,ao,sum : char; {ao = arithmetic operation}
    realnumber : integer;
    index : indexType;
    Procedure Read_Romans_Numbers_to_Real;
    BEGIN
    For RomansNu := I TO M DO
    begin
    writeln('Enter The First Number: '); readln(first);
    Case first Of
    'I':begin realnumber := 1; end;
    'V':begin realnumber := 5; end;
    'X':begin realnumber := 10; end;
    'L':begin realnumber := 50; end;
    'C':begin realnumber := 100; end;
    'D':begin realnumber := 500; end;
    'M':begin realnumber := 1000; end
    else writeln('Roman Numerals Are Just I,V,X,L,C,D,M');

    writeln('The First Number is',realnumber);
    write('Enter The Second Number:'); readln(second);
    Case second Of
    'I':begin realnumber := 1; end;
    'V':begin realnumber := 5; end;
    'X':begin realnumber := 10; end;
    'L':begin realnumber := 50; end;
    'C':begin realnumber := 100; end;
    'D':begin realnumber := 500; end;
    'M':begin realnumber := 1000; end
    else writeln('Roman Numerals Are Just I,V,X,L,C,D,M');
    end;
    writeln('The Second Number is',realnumber);
    end;
    write('Enter The Arithmetic Operation:'); readln(ao);
    Case ao of
    '+': begin sum := 'first'+'second'; end;
    '-': begin sum := 'first'-'second'; end;
    '*': begin sum := 'first'*'second'; end;
    '/': begin sum := 'first'/'second'; end
    else writeln('The Arithmetic Operations are +,-,*,/.');
    end;
    write('The Sum Of ',first,'and',second,'is',sum);
    End;
    End;


  • [b][red]This message was edited by Perran at 2004-1-2 5:21:41[/red][/b][hr]
    : : : Hi
    : : : I want help to solve this problem in pascal:
    : : :
    : : : In this problem you will design and implement a Roman numeral calculator. Most people are unaware that the subtractive Roman numeral notation commonly in use today (such as IV Meaning 4) was only rarely used during the time of the Roman Republic and Empire. For ease of calculation, the Romans most frequently used a purely additive notation in which a number was simply the sum of its digits (4 equals IIII in this notation).
    : : : Each number starts with the digit of highest value and ends with the one of smallest value. This is the notation we will use in this problem.
    : : :
    : : : Your program will input two Roman numbers and an arithmetic operator and print out the result of the operation, also as a Roman number. The values of the Roman digits are as follows:
    : : :
    : : : I 1
    : : : V 5
    : : : X 10
    : : : L 50
    : : : C 100
    : : : D 500
    : : : M 1000
    : : :
    : : : Thus, the number MDCCCCLXXXVIIII represents 1989. The arithmetic operators that your program should recognize in the input are +, -, * and /. These should perform the Pascal operations of integer addition, subtraction, multiplication and division.
    : : :
    : : : One way of approaching this problem is to convert the Roman numbers into integers, perform the required operation, and then convert the result back into Roman number for printing. The following might be a sample run of the program, for an interactive system.
    : : :
    : : : Enter the first number:
    : : : MCCXXVI
    : : : The first number is 1226
    : : : Enter the second number:
    : : : LXVIIII
    : : : The second number is 69
    : : : Enter the desired arithmetic operation:
    : : : +
    : : : The sum of MCCXXVI and LXVIIII is MCCLXXXXV (1295)
    : : :
    : : : Your program should use a good style, appropriate comments, meaningful identifiers, proper indentation and avoid side effects.
    : : :
    : : : It should also check for errors in the input, such as illegal digits or arithmetic operators and take appropriate actions when these are found. You may also have the program check to be sure that the numbers are in purely additive forms – digits are followed only by digits of the same or lower value.
    : : :
    : : : And I have to do the problem with just this sections:Choice Statements, Loop Statements, Procedures and Functions,Subrange,Arrays,Enumarated types,TextFiles and Records.
    : : :
    : : :
    : : The way it works is: you try to write some code and then post it back when you run into trouble. Someone might help you then. Simply copy/pasting from your syllabus into a message like this won't cut it.
    : :
    : One Example That I did Is like that but doesn't work(It Gives Type Mismatch):
    : PROGRAM Roman_Calculator;
    : TYPE
    : indexType = 1..7;
    : RomanNumberArray = array [indexType] of char;
    : RomansNumbers = (I,V,X,L,C,D,M);
    :
    : VAR
    : RomansNu : RomansNumbers;
    : RomansNo : RomanNumberArray;
    : first,second,ao,sum : char; {ao = arithmetic operation}
    : realnumber : integer;
    : index : indexType;
    : Procedure Read_Romans_Numbers_to_Real;
    : BEGIN
    : For RomansNu := I TO M DO
    : begin
    : writeln('Enter The First Number: '); readln(first);
    : Case first Of
    : 'I':begin realnumber := 1; end;
    : 'V':begin realnumber := 5; end;
    : 'X':begin realnumber := 10; end;
    : 'L':begin realnumber := 50; end;
    : 'C':begin realnumber := 100; end;
    : 'D':begin realnumber := 500; end;
    : 'M':begin realnumber := 1000; end
    : else writeln('Roman Numerals Are Just I,V,X,L,C,D,M');
    :
    : writeln('The First Number is',realnumber);
    : write('Enter The Second Number:'); readln(second);
    : Case second Of
    : 'I':begin realnumber := 1; end;
    : 'V':begin realnumber := 5; end;
    : 'X':begin realnumber := 10; end;
    : 'L':begin realnumber := 50; end;
    : 'C':begin realnumber := 100; end;
    : 'D':begin realnumber := 500; end;
    : 'M':begin realnumber := 1000; end
    : else writeln('Roman Numerals Are Just I,V,X,L,C,D,M');
    : end;
    : writeln('The Second Number is',realnumber);
    : end;
    : write('Enter The Arithmetic Operation:'); readln(ao);
    : Case ao of
    : '+': begin sum := 'first'+'second'; end;
    : '-': begin sum := 'first'-'second'; end;
    : '*': begin sum := 'first'*'second'; end;
    : '/': begin sum := 'first'/'second'; end
    : else writeln('The Arithmetic Operations are +,-,*,/.');
    : end;
    : write('The Sum Of ',first,'and',second,'is',sum);
    : End;
    : End;
    :
    :
    :
    It's because you're trying to do mathematical operations on strings and trying to assign the results to a variable of char type. You will want to do your math on realnumber, but it's getting assigned to twice. Try using realnumber1, and realnumber2 or something like that. Replace 'first' and 'second' in the [b]case ao[/b] block with those variables. The [b]begin..end[/b] pairs are not necessary in any of your case statements. I really don't see the need for the [b]for..to..do[/b]loop. Your case statements should handle it. Otherwise, a good try :-)


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories