CSCI 150, Spring 2003
Home | | Course Schedule | | Assignments | | Lecture NotesLab 3 solution
{program: calc1.pas Author: Brenda Student Class: CSCI 150, Section 03 Date: 2/5/03 Assignment: Lab 3 Purpose: Takes in 2 numbers and an operator. Performs specified arithmetic operation.} program calc; var num1: real; {First number} num2: real; {Second number} answer: real; {Computed answer} opcode: char; {Operation to be performed} continue: string; {answer to question 'Do you want to continue?'} begin writeln('Do you want to perform a calculation?'); readln(continue); while continue = 'yes' do begin writeln('Please enter the first number:'); readln(num1); writeln('Please enter the second number:'); readln(num2); writeln('Please enter the operator (+,-,* or /):'); readln(opcode); if opcode = '+' then begin answer := num1 + num2; end else if opcode = '-' then begin answer := num1 - num2; end else if opcode = '*' then begin answer := num1 * num2; end else if opcode = '/' then begin answer := num1 / num2; end else begin answer:= 0; writeln('That is not a valid operator.'); end; writeln('The result is ', answer:10:2); writeln('Do you want to perform another calculation?'); readln(continue); end; writeln('Thank you and goodbye!'); end. {end calc program}