2 Replies - 357 Views - Last Post: 05 September 2017 - 05:10 PM Rate Topic: -----

#1 RodriFING  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-September 17

Reading strings of characters

Posted 05 September 2017 - 03:49 PM

Ive been tasked to write a program that is given a entry of this type X:A..Were X is a number from 2-16 followed by : and A is a string of numbers and/or caps letters FOLLOWED BY A DOT. The program returns a number. EXample: INPUT 2:2A. OUTPUT 2*2^1+10*2^0 = 14.

I have writen most of my code ,all the operations I have to do ,however I dont know how to read the enty in the correct way so the rest of my code is useless. We have been told to read the entry as two chars however when I try it as the first thing is a nuber it say expected char but found shorint.

How do I do this?

Is This A Good Question/Topic? 0
  • +

Replies To: Reading strings of characters

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,857
  • Joined: 12-June 08

Re: Reading strings of characters

Posted 05 September 2017 - 04:24 PM

Show folk the code of what you tried, the result, and how that differs from what you want.
Was This Post Helpful? 0
  • +
  • -

#3 RodriFING  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-September 17

Re: Reading strings of characters

Posted 05 September 2017 - 05:10 PM

View Postmodi123_1, on 05 September 2017 - 04:24 PM, said:

Show folk the code of what you tried, the result, and how that differs from what you want.


This is the chunk of code thats giving me trouble

const A = 10
      B = 11
      C = 12
      D = 13
      E = 14
      F = 15

var base,digits : char;
    num: LongInt;

begin

num:=0;
read(base,digits);

while(base <> '$') do
 begin

     num:=(num * base)+digits;
     writeln(num);
     read(base,digits)
  end;


An example of an entry would be 5:A3F. My guess of why im having trouble with is that it doesnt read each individual character from digits plus I have to ignore the ":" and "."

Thanks for the help and sorry if my question is dumb I am a beginner
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1