Print questions from a questions folder in a sequential order


 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Print questions from a questions folder in a sequential order
# 8  
Old 12-01-2010
Code:
do
print "Enter question number, N for next question, P for previous question or Q for done"
read a
...

Why did you use echo in the first test and suddenly "print" instead?
# 9  
Old 12-01-2010
replace print by echo

By the way, read the error message : print expect a file and find something whereas "...." is a string (no such file error)
# 10  
Old 12-13-2010
referring to the code above,how can output my answers and confirm it. the file fileuseranswer does not have the output there, instead it has:
2 n
3 n
4 n
5 n
..etc and I don't know why?
My priority is to be able to confirm the output of the test and displaying the total.
e.g "You got 5 out of 8"
# 11  
Old 12-13-2010
Well we dont know how your code is now... (did you replace print by echo?... what else has been done since?)
# 12  
Old 12-14-2010
I added some line of code for the saving and outputing my result to the filuseranswer file,but was not successful.here is code:

Code:
#!/bin/sh
touch fileuseranswer
 echo "**********WELCOME TO GROUCHO MARX UNIVERSITY**********"

echo Username:
read i
echo Password:
read j
Username="${i}:${j}"
 
if ( ! grep -q $Username /$HOME/PhaseTest/userinfo )
then
        echo "Wrong Login/Passwd"
        exit 2
fi
 


echo 
echo -e "                    \c"
date
QFILE=./questions
# max questions
max=$(sed 's/^[1-8][0-8]*\. /#&/' ${QFILE} | nawk -v FS="\n" -v RS="#" 'END {print NR}')
 
question(){
clear
sed 's/^[1-8][0-8]*\. /#&/' ${QFILE} | awk -v FS="\n" -v RS="#" -v VAR="$1" '(NR==VAR){print$0}' | tee q.tmp
#sed -n '/^'`echo "$1"`'\./,/^d) /p' ${QFILE}
 
while :
do
echo "Enter your choice :"
read b
if ( ! grep "$b"')' q.tmp >/dev/null ) ; then
        echo "Invalid choice"
        rm q.tmp
        RC=1 ; break
else
        rm q.tmp
        grep -v ^$1 fileuseranswer >fileuseranswer.tmp
        echo "$1 $a" >>fileuseranswer.tmp
        cat fileuseranswer.tmp >fileuseranswer
        rm fileuseranswer.tmp
        RC=0 ; break
fi
done
return $RC
}
 
while :
do
echo -e "Enter question number, N for next question, P for previous question or Q for done"
read a
case $a in
        [1-8]*) [[ $a -gt $max ]] && c=$max || c=$a ; question "$c" ;;
        n|N) [[ $c -lt $max ]] && let c+=1 || let c=1 ; question "$c" ;;
        p|P) [[ $c -ge 1 ]] && let c-=1 || let c=$max ; question "$c" ;;
        q|Q) exit 0 ;;
        *) echo "Wrong choice , try again" ;;
esac
done

answers(){
 echo -e "\c" > fileuseranswer 
    QNUM=0 
    TOTAL=0 
    while [ $QNUM -lt ${#questions[@]} ] 
    do 
        echo "\"${FILEUSERANSWER[$QNUM]}\" " >> fileuseranswer 
        [ "${CORRECT[$QNUM]}" = "${FILEUSERANSWER[$QNUM]}" ] && let SCORE=SCORE+1 
        let QNUM=QNUM+1 
    done 
    echo "You got $TOTAL questions correct out of ${#questions[@]}" 
}

Please to troubleshoot it.I've gone out of ideas.

Thanks

Last edited by vbe; 12-14-2010 at 09:20 AM.. Reason: Dont forget the code tags!
# 13  
Old 12-14-2010
Code:
echo "$1 $a" >>fileuseranswer.tmp

should be replaced by

Code:
echo "$1 $b" >>fileuseranswer.tmp

your answers(){ ... } function is useless since not called anywhere.

Last edited by ctsgnb; 12-14-2010 at 10:46 AM..
This User Gave Thanks to ctsgnb For This Post:
# 14  
Old 12-14-2010
You're Awesome.Thanks its works quiet all right.
1.)I tried adjusting the line of code for the questions because it displays "Enter question number, N for next question, P for previous question or Q for done" at the beginning of the question instead of displaying question 1 and asking for "Enter...." after then.
2.)I need help on how to end the questions at question 8
3.)To be able to go to a previous question done without being able to change the answer

Thanks a lot.Your help is appreciated.

Last edited by moraks007; 12-14-2010 at 12:51 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print missing and keep sequential ordering if not found

The below awk in bold will look for the ids in file1 in $2 of file2 and if they match print the line in file2. If an id is missing or not found in file2 (like BMPR2 in line4 of file1) I can not figure out how to add it to them to the lines in the output as missing in $3 following the same format.... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. UNIX for Dummies Questions & Answers

Vi questions

Hello, I would like to know how we can highlight/select a section of a file in vi and delete that section if we don't want to use the dd command to delete one line at at time. There is one where we don't want to delete the whole line , but up to a certain word. (2 Replies)
Discussion started by: Pouchie1
2 Replies

3. Programming

C++ questions

1.) Let's say I have a list: apple1, apple2, apple3, apple4, apple5 Does anyone know how to display the txt file using c++? Does anyone know how to insert apple6 into the text file using link list and show the whole list including apple6? (1 Reply)
Discussion started by: bscot008
1 Replies

4. Programming

A few C questions

Hi guys. I'm writing a basic script in C# and there's a few areas where I am stuck, and I was wondering if you may be able to help me? 1) Can you embed an image into the source code so it will show in the windows GUI? 2) Can you change the background of the GUI? 3) How do you add an .ico to... (5 Replies)
Discussion started by: JayC89
5 Replies

5. Programming

Reading special characters while converting sequential file to line sequential

We have to convert a sequential file to a 80 char line sequential file (HP UX platform).The sequential file contains special characters. which after conversion of the file to line sequential are getting coverted into "new line" or "tab" and file is getting distorted. Is there any way to read these... (2 Replies)
Discussion started by: Rajeshsu
2 Replies

6. AIX

Basic AIX Print Queue Questions

Morning, All I've been doing some work on AIX print queues, troubleshooting some underlying issues we've been having. In the process of this I've uncovered some potential gaps in our knowledge. Our typical setup is remote impact printers (In this case OKIML5520s, with NICs) and local queues... (0 Replies)
Discussion started by: alexop
0 Replies

7. UNIX for Dummies Questions & Answers

few questions

hi , i have got few questions 1) i created a file "-myfile" .how can i remove this?what command shud i issue 2) i used echo "TODAYS DATE" ; DATE..........but date is comoing in second line..how can i make it come in single line? 3) how can i list all files in a directory using for... (5 Replies)
Discussion started by: vivekshankar
5 Replies

8. UNIX for Dummies Questions & Answers

questions

Dear Guys , I have some Questions , i need to have answeres for . 1. now if i took a back up for /etc/passwd and /etc/shadow , like simple copy .. and Install a new system , and paste those two files to the new system ... are the passwords and user info. going to work ?? is it posibble ? ... (1 Reply)
Discussion started by: tamemi
1 Replies

9. Programming

C questions

What does "extern" do? ex. extern int x; and another question, what about using static in functions? like: static void foo(), why? (2 Replies)
Discussion started by: Esaia
2 Replies
Login or Register to Ask a Question