LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-21-2017, 09:47 AM   #16
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled

What kind of "help" does the OP require?
You know the "what", so can we assume you don't know "how"?

Catching user input has several examples you can work up.
Ask if you get stuck.
 
Old 02-21-2017, 09:48 AM   #17
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Eh, as always, in every language, coding is easy
Figuring out how to make the code do what you want is what turns your hair grey.
That's probably what his teacher is looking for, in which case we just did most of his homework.

@Habitual
In shell, user input can be acomplished on the command line. He doesn't say "ask for user input", he says "create a bash script that takes an integer"
which I'm interpreting to mean "./myscript.sh 32 " would suffice. Global/built in var $1 would then contain the number 32

Last edited by dijetlo; 02-21-2017 at 10:08 AM.
 
Old 02-21-2017, 09:49 AM   #18
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
I do not even know why I jumped in on this alleged invalid homework question. Oh yeah, Just sharing my thoughts on it like everyone else. .. shutting up on this question :mode: ON

Last edited by BW-userx; 02-21-2017 at 09:51 AM.
 
Old 02-21-2017, 10:04 AM   #19
dijetlo
Senior Member
 
Registered: Jan 2009
Location: RHELtopia....
Distribution: Solaris 11.2/Slackware/RHEL/
Posts: 1,491
Blog Entries: 2

Rep: Reputation: Disabled
Goodness, don't do that.
You looked at this problem and offered an opinion
Someone else looked at it differently and disagreed
We could very well be in reverse positions next time
and since the purpose of this board is to provide knowledge and understanding, your participation in the conversation is invaluable (or at the very least, just as valuable as mine).
 
Old 02-21-2017, 10:05 AM   #20
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I'd like to remind everyone that while it is fair to note to a new poster that they have asked a poor question, as advice givers we all should be practicing a few things:
  1. Restraint with the unhelpful and critical comments
  2. We should welcome the new poster and give them information related to how best to re-shape their question
  3. We should perhaps offer some links relevant to their task at hand
  4. Members should consider being silent and allow a first time poster to have the time to respond back with updates. Another reason for this is that sometimes there are new members who ask for direct help by way of asking for full code and support and when they're informed that the LQ site does not work in this manner, they will no longer respond. This can help avoid frustration on the part of advice givers, should avoid continued negative comments which serve no one, and in the possible event that max-shah just hasn't gotten back to respond as yet, the fewer insults or negative comments, the better the picture may be for when they decide to put forth some effort to show their attempts or update their question with more details
 
1 members found this post helpful.
Old 02-21-2017, 10:22 AM   #21
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
you mean something like this?

Program to convert a given number to words


It is C
It can be converted into BASH Script. Arrays, Functions, Loops and Conditionals can be done in Bash Script or is that too much Information?

Last edited by BW-userx; 02-21-2017 at 10:29 AM.
 
1 members found this post helpful.
Old 02-21-2017, 11:09 AM   #22
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
And this if @max-shah the OP should ever come back, should be enough to get him started on his path of self knowledge about BASH Scripting.

Have fun

Code:
#!/bin/bash
#Bash script to convert numbers into words

function Covert_num_2_words {

chrlen="$number"

 if [[ ${#chrlen} -eq 0 ]] ; then
  printf "Empty String\n"
  retutn 1
 fi
 
 if [[ ${#chrlen} -gt 4 ]] ; then
  printf "Length greater than 4 not supported\n"
  return 1
 fi
 
 single_digits=("zero" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine")
 
 two_digits=("" "ten", "eleven" "twelve" "thirteen" "fourteen" "fifteen" "sixteen" "seventeen" "eighteen" "nineteen")
                     
 ten_multiple=("" "" "twenty" "thirty" "forty" "fifty" "sixty" "seventy" "eighty" "ninety")
                             
 ten_power=("hundred" "thousand")
 
#debugging
printf "\n Number: $number\n"
printf "${#chrlen}\n"

 if [[ ${#chrlen} == 1 ]] ;then 
  printf "single_digits[$number - 0]\n"
  printf ""${single_digits[$number]}"\n"
 fi



}


read -p 'Enter a number ' number

Covert_num_2_words number
Remember Arrays are zero based.

results;
Quote:
(userx@SlackO⚡️~/test)>>$ ls
ConvertNumbersIntoWords a.out dependencies h homework1 main.cpp
(userx@SlackO⚡️~/test)>>$ ./ConvertNumbersIntoWords
Enter a number 7

Number: 7
1
single_digits[7 - 0]
seven
(userx@SlackO⚡️~/test)>>$

Last edited by BW-userx; 02-21-2017 at 11:22 AM.
 
1 members found this post helpful.
Old 02-21-2017, 12:41 PM   #23
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
A creative solution would be to pass the number to a text-to-speech program, and then pipe the resulting audio to a speech-to-text program configured to use words for numbers.
 
Old 02-21-2017, 01:03 PM   #24
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
right then set it up to speak to a voice recognition type writer and have it type it out then send it to a scanner for processing with word recognition software and have it send that to a program that can store it in a file for you.
 
Old 02-21-2017, 02:16 PM   #25
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by rknichols View Post
A creative solution would be to pass the number to a text-to-speech program, and then pipe the resulting audio to a speech-to-text program configured to use words for numbers.
Done:

just add this to the code: it is actually text to speech so it is a half baked idea .. Lololo
Code:
 if [[ ${#chrlen} == 1 ]] ;then 
  printf "single_digits[$number - 0]\n"
  printf ""${single_digits[$number]}"\n"
  espeak "${single_digits[$number]}"
fi

Last edited by BW-userx; 02-21-2017 at 02:20 PM.
 
Old 02-21-2017, 03:19 PM   #26
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Please everyone, let's keep our comments on topic and allow the OP to digest and respond to comments posted to this point.
 
Old 02-21-2017, 05:11 PM   #27
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Basically ...

(1) "Pick a programming language ... any(!) programming language!" (I can truthfully say that I solved this same problem thirty-five years ago in HP2000 Access BASIC.)

(2) The essence of this problem is nothing more than a very-trivial exercise in integer arithmetic ... the integer-division and integer-modulous operators. Once you have succeeded in breaking down "135" into "1," "3," and "5," you're home free.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
seeking USB connected audio input and output "box" SaintDanBert Linux - Hardware 4 08-08-2012 04:42 PM
Right-side-of-thirty "British" (I hate that word) Male GrubbySeismic LinuxQuestions.org Member Intro 4 01-15-2010 10:24 PM
"failed to execute child process" "Input/output error" fl.bratu Fedora 4 12-15-2008 04:03 AM
"/usr/bin/ls: reading directory .: Input/output error" DiZi Slackware 15 07-13-2008 10:03 AM
C program that takes input "FName|LName" and outputs to std out its_godzilla Programming 2 01-18-2005 10:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration