LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-19-2018, 04:24 PM   #1
linuxnoob22
LQ Newbie
 
Registered: Mar 2018
Posts: 5

Rep: Reputation: Disabled
School Test Question Help


This is a question on my test and I was wondering if any of you experts would know how I could start something like this. Thank you for your time!

Write a shell script that uses a loop to build a table of Fahrenheit temperatures and the corresponding Celsius temperatures. The script must meet these requirements:

a. The script must ask the user for the starting Fahrenheit temperature, ending Fahrenheit temperature and increment.

b. To calculate the Celsius temperature use the formula °C = (°F - 32) x 5/9

c. The table should have the headings "Degrees F" and "Degrees C"

d. The left hand column of the table should contain Fahrenheit temperature; the right column should contain the corresponding Celsius temperature.

e. You do NOT need to check for an infinite loop. You can assume that the user will provide reasonable input.
 
Old 03-19-2018, 04:39 PM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
What have you done so far?

If nothing, try first writing the solution as an algorithm in English words rather than using shell script.
 
Old 03-19-2018, 04:53 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by linuxnoob22 View Post
This is a question on my test and I was wondering if any of you experts would know how I could start something like this. Thank you for your time!

Write a shell script that uses a loop to build a table of Fahrenheit temperatures and the corresponding Celsius temperatures. The script must meet these requirements:

a. The script must ask the user for the starting Fahrenheit temperature, ending Fahrenheit temperature and increment.
b. To calculate the Celsius temperature use the formula °C = (°F - 32) x 5/9
c. The table should have the headings "Degrees F" and "Degrees C"
d. The left hand column of the table should contain Fahrenheit temperature; the right column should contain the corresponding Celsius temperature.
e. You do NOT need to check for an infinite loop. You can assume that the user will provide reasonable input.
Yes; you can start by reading your textbook, looking at any of the many thousands of bash scripting guides you can find, and begin there. You need to read the LQ Rules and the "Question Guidelines" link. We're happy to help, but we aren't ever going to write scripts or do your homework for you.

That said, as hydrurga pointed out, writing things out in plain english often helps. Think about each step, and what it will take to accomplish it. For example:

a. "Ask the user" = prompt for user input and read it. Going to read three variables (start, end, and increment). Search for "how to read user input in bash scripting"
b. You have a formula, so you know how to perform math. Search for "how to perform math in bash scripting".
b1. You have a start/end range...this means you have to loop through all of them. Search for "how to loop within a bash script"
c. You have to print output. Search for "how to print bash script output to screen"
d. Same search as c
e. Nothing to do.

Start there.
 
1 members found this post helpful.
Old 03-19-2018, 05:35 PM   #4
linuxnoob22
LQ Newbie
 
Registered: Mar 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
if i had time, i would do that. However i do not have the time...that's why i made a post here. Thanks for your not very helpful advice tho!
 
Old 03-19-2018, 05:42 PM   #5
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
Quote:
b. To calculate the Celsius temperature use the formula °C = (°F - 32) x 5/9
If you are considering using 'bash', a little wrinkle is that (from 'man bash')
Quote:
Evaluation is done in fixed-width integers with no check for overflow, though division by 0 is trapped and flagged as an error.
Perhaps there are extra points for considering rounding errors.
 
Old 03-19-2018, 05:53 PM   #6
linuxnoob22
LQ Newbie
 
Registered: Mar 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
This is what i have so far:

Quote:
#!/bin/bash

echo "Enter starting Fahrenheit temperature:"

read sf

echo "Enter end Fahrenheit temperature:"

red ef

echo "Enter the step increment:"

read step

echo "Fahrenheit Celsius"

while [ $sf -lt ef ]

do

c=`expr ($sf-32)*5/9

echo "$sf $c"

sf=`expr $sf+$step

done
i get an error on line 19 and 22
 
Old 03-19-2018, 07:33 PM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
check spelling code...
You may want to use bc instead of expr when dealing with decimal numbers
 
Old 03-19-2018, 07:37 PM   #8
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
The OP's code, remarkably quickly written given their initial lack of knowledge, was lifted in its entirety from here (spelling mistakes and all):

https://stackoverflow.com/questions/...-celsius-error

To the OP, it is not going to help your education in any way if we hand-feed you answers to your homework questions. You should at least put in some effort.
 
3 members found this post helpful.
Old 03-19-2018, 07:46 PM   #9
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by hydrurga View Post
The OP's code, remarkably quickly written given their initial lack of knowledge, ...
...and attitude
 
1 members found this post helpful.
Old 03-19-2018, 07:50 PM   #10
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Wow, nice catch...
I am surprised that the slackoverflow suggestion keeps going with the while loop route as inputed values seems to fit better in a for loop. But I aggree with the possible perl or python use
 
Old 03-19-2018, 08:11 PM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
How can I say this politely ...?

I sense that you might be a by-product of that awful educational travesty called "No Child Left Behind™," which very-successfully sold the world on the notions that:
  • ... the world consists of standardized tests, and
  • ... you are entitled to succeed, and
  • ... you can sue your teacher if you don't.


This week, I plan to use the money that I will earn from several decades of software experience to pay "a wizard with a backhoe" to fix my driveway, before I pay another expert to tackle a metal roof, and another to tackle a leaking chimney.

It so happens that, from my earliest childhood, "computers" were – and, still are(!) – a genuine (software-only ...) fascination for me. Therefore, I was – and, I still am – self-driven.

If(!) "this computer software thing" is seriously "what you are interested in doing," then ... do it, yourself!

... otherwise, "please pick something else to do, while there's still time."

Last edited by sundialsvcs; 03-19-2018 at 08:21 PM.
 
2 members found this post helpful.
Old 03-20-2018, 07:17 AM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by linuxnoob22 View Post
if i had time, i would do that. However i do not have the time...that's why i made a post here. Thanks for your not very helpful advice tho!
Getting someone to do your homework for you because you 'do not have the time' won't get you help. Your schedule and lack of planning doesn't make this an issue for us. Neither will your snotty comment about the 'not very helpful advice' get you far.

If you want to learn and show effort, you're in the right place. If you want a handout, go elsewhere.
 
Old 03-20-2018, 07:23 AM   #13
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
@linuxnoob22,

Please stop posting your test and homework assignment questions, showing no effort. LQ is a friendly site, however not about doing work for you.

All members are volunteers and are willing to help, including with homework assignments. A stated guideline in the LQ Rules is that you do not post homework or test questions verbatim, with one reason being that your instructor may be a LQ member.

The other guidelines are that you need to show some effort with your assignments.

If you wish to solely ask for answers and receive them, then the LQ site is not for you.
 
1 members found this post helpful.
Old 03-20-2018, 08:09 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
additionally you may try to use shellcheck.net to check your script
 
  


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
Sample question for school project LoganK Linux - Newbie 12 10-17-2014 11:08 AM
LXer: SprezzOS emerges, promising new-school tech with old-school gumption LXer Syndicated Linux News 0 02-01-2013 11:33 PM
Old School Question: Remote Xdisplay glancebe Linux - Desktop 3 03-09-2011 08:10 AM
LXer: Skegness Grammar School, using GNU/Linux and thin-clients across the school LXer Syndicated Linux News 0 08-23-2008 11:00 PM
school is going to test and than switch!!! trinity04 Linux - Software 12 10-11-2004 01:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:33 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