How Can a Single READ Statement Handle Multiple Data Types in Programming?

  • Context: Fortran 
  • Thread starter Thread starter cibui
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary

Discussion Overview

The discussion centers on how a READ statement in programming can handle multiple data types, specifically focusing on reading both numerical values and function names from user input. Participants explore the challenges of parsing input that includes continuous functions and operable numbers.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant questions how to use a READ statement to accept both numbers and function names simultaneously, citing a specific example of a continuous function like sin(x).
  • Another participant suggests that parsing input to recognize function names is complex and may be challenging for someone without programming experience.
  • A later reply clarifies that while a READ statement can read numbers and strings, it cannot directly interpret functions without additional logic to parse the input.
  • One participant expresses concern about how to handle operable numbers within function names, such as sin2x, and questions whether a READ statement can process these correctly.
  • Another participant reiterates that all input will initially be read as a string, necessitating further logic to separate function names from their arguments.

Areas of Agreement / Disagreement

Participants generally agree that a single READ statement cannot directly handle both functions and numbers without additional parsing logic. However, there is some disagreement regarding the feasibility of implementing such logic for someone without programming experience.

Contextual Notes

Limitations include the assumption that the input must be parsed correctly to differentiate between function names and numerical arguments, as well as the potential complexity involved for beginners in programming.

Who May Find This Useful

This discussion may be useful for individuals interested in programming input handling, particularly those exploring how to manage user input that includes both numerical and functional data types.

cibui
Messages
8
Reaction score
0
Hi guys,

straight to the point, how do you make your READ statement to be able to read both numbers and letters(words) or functions at the same time? okay, for example, i want the user to input a continuous function. what if the function is, let say, sin(x)? do i need to break the READ statement into several READ statements or it can be done with only one statement? i was only taught to use "READ *, " but never told how does this really work.

I'm no programmer and have no programming background, so please help me :redface:
greatly appreciated
 
Last edited:
Technology news on Phys.org
This is a harder problem than you might realize, since your program has to parse the input text to recognize function names.

A READ statement can be set up to read numbers (either real or integer) or strings of characters. It can't be set up to read functions such as sqrt or sin. There must be logic in the program to match input strings to a list of functions. If you have no programming experience, this will probably be beyond your abilities.
 
Thanks for the reply Mark,
okay, so it is not possible afterall...
guess i will have to break the input structure into several steps then

anyway tyvm
 
I didn't say it wasn't possible. I said that with your lack of experience it would be very difficult.

In your first post you talked about "break(ing) the READ statement into several READ statements..." That's not what you need to do.

Your program needs to read the input as a string, and then it needs to parse the string to determine if the input string contains the name of a function, such as sin, or tan, or ln, or whatever.
 
i know that read statement can read strings of texts but the thing is what if it involves operable numbers? e.g. sin2x. i want it so that the inputted "2" by the user can be processed by the program as an operable number not as a part of a string of text. can READ actually do that?
thanks for your help
 
Everything will necessarily have to come into the program as a string of characters. In your example, if the user enters sin2x, your program will read this as a character string. Your program will then have to have logic so that it can separate out the function name (sin) from the argument (2x).
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 18 ·
Replies
18
Views
17K
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K