Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
I NEED HELP WITH 4.2 Practice Question 11!
Author Message
master-awesome

Posted: Fri Nov 14, 2014 4:26 pm   Post subject: I NEED HELP WITH 4.2 Practice Question 11!

The question is "Write a program that accepts 3 numbers from the user and then shows them in ascending or descending order (based on the user?s choice)."

I've spend hours and hours trying to figure this out and I'm at the point where I even want to ignore this question, but my teacher isn't much help and the students in my class are struggling equally hard, but considering all this, the teacher still refuses to help.

I don't know what to do and I'm beginning to hate this course because I'm left so confused and everybody thinks I should keep going because I get good marks in it. This really sucks! HELP ME PLEASE!

Here's my program:

Quote:
var A1 : real
var A2 : real
var A3 : real
var D1 : real
var D2 : real
var D3 : real
var result1 : string
var result2 : string
result1 := "Good! You will have to arrange your number from smallest to biggest for ascending!"
result2 := "Good! You will have to arrange your numbers from biggest to smallest for descending!"

put "Would you like to put your number in ascending or descending order? "
..put " Write \"A\" for ascending and \"D\" for descending."

else
put ""
end if

put result1
get A1,A2,A3
else
put ""
end if

put result2
get A1,A2,A3
else
put ""
end if

if A1 > A2 and A1 > A3 then
colour (2)
put "The number ",A1," is the highest!"
else
colour (12)
put ""
end if

if A2 > A3 and A2 < A1 then
colour (2)
put "The number ",A2," is the medium!"
else
colour (12)
put ""
end if

if A3 < A2 and A3 < A1 then
colour (2)
put "The number ",A3," is the smallest!"
else
colour (12)
put ""
end if

if A1 < A2 and A1 < A3 then
colour (2)
put "The number ",A1," is the smallest!"
else
colour (12)
put ""
end if

if A2 > A1 and A2 < A3 then
colour (2)
put "The number ",A2," is the medium!"
else
colour (12)
put ""
end if

if A3 > A1 and A3 > A2 then
put "The number ",A3," is the highest!"
else
colour (12)
put ""
end if

Tony

Posted: Fri Nov 14, 2014 4:56 pm   Post subject: RE:I NEED HELP WITH 4.2 Practice Question 11!

I've moved this topic to Turing Help from General Discussion.

When you say
Quote:

the teacher still refuses to help.

The approaches to this problem are also wildly different depending on the usage of arrays -- if you've already covered those in class, it's probably a good idea to use them. If not, that's okay too, this is totally solvable.

For some inspiration, it might help to find a deck of cards, pick out 3 numbered cards, and arrange them in order. It's a simple task, the difficult part is noticing exactly what you are doing -- what "variables" are you remembering? What kind of comparisons are you doing between cards? If you write down the steps you took, and try it again with a different set of 3 cards, would that also work?
Tony's programming blog. DWITE - a programming contest.
master-awesome

Posted: Fri Nov 14, 2014 5:57 pm   Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!

This is how it is supposed to work.
Quote:
I type:
10
5
8

And then the user has a choice to ascend like so:

Quote:
5
8
10

or descend like so

Quote:
10
8
5
Tony

Posted: Sat Nov 15, 2014 12:56 am   Post subject: RE:I NEED HELP WITH 4.2 Practice Question 11!

Using a specific example is a good start.
Tony's programming blog. DWITE - a programming contest.
master-awesome

Posted: Sat Nov 15, 2014 11:11 am   Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!

Okay so what happens is the user types in three numbers. For example:
Quote:
5
8
2

Now what happens is the user has a choice of deciding whether he/she wants it descending or ascending.

Quote:
So would you like your number ascending or descending. Type in D for descending or A for ascending!

If the user punches A then this will happen!
2
5
8

Quote:
If the user punches D then this will happen!

8
5
2
Insectoid

Posted: Sat Nov 15, 2014 11:19 am   Post subject: RE:I NEED HELP WITH 4.2 Practice Question 11!

We know what the assignment is asking for. Most of us did the same one when we were in high school. Tony is asking that *you* play around with a deck of cards. Take 3 cards in random order and sort them. The hard part is, like Tony said, figuring out exactly what you did to sort them in a way that a computer can understand. This can be done in as little as two if statements.
master-awesome

Posted: Sat Nov 15, 2014 11:29 am   Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!

I'm kind of lost here! I don't know how the deck of cards work. Could you show me an example here?

4.2 Practice Question 11.t
Description:
Filename:  4.2 Practice Question 11.t
Filesize:  1.57 KB

Tony

Posted: Sat Nov 15, 2014 3:34 pm   Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!

master-awesome @ Sat Nov 15, 2014 11:29 am wrote:
I don't know how the deck of cards work.

It's just some pieces of paper with numbers on them. It could be helpful connection to "the real world", as you talk your way through the problem.

You keep on giving examples like going from 5,8,2 to 2,5,8 (ascending), but what were the steps in the middle? How did you know that the first number is a 2, instead of a 5 or an 8? This is the kind of very specific steps that you have to explain to a computer in code.
Tony's programming blog. DWITE - a programming contest.

master-awesome

Posted: Sat Nov 15, 2014 5:24 pm   Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!

But how do you explain to the computer the code?

Do you need randint or is this if statements?

4.2 Practice Question 11.t
Description:
Filename:  4.2 Practice Question 11.t
Filesize:  752 Bytes

Panphobia

Posted: Sat Nov 15, 2014 11:31 pm   Post subject: RE:I NEED HELP WITH 4.2 Practice Question 11!

If it is only 3 cards, if statements are enough but not the optimal solution. Imagine having 5 different cards in front of you in a random order. How would you sort them in descending order? What would be your first step? By the way, have you learned loops yet?
master-awesome

Posted: Sun Nov 16, 2014 11:30 am   Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!

How would loops apply here? Could you show me the code or something so I understand better?
Insectoid

Posted: Sun Nov 16, 2014 4:20 pm   Post subject: RE:I NEED HELP WITH 4.2 Practice Question 11!

You have to understand at all before you can understand better. I mean, you asked you need to use randint. Is there anything random in this program? This really shows that you haven't put any real thought into this at all.
master-awesome

Posted: Mon Nov 17, 2014 12:55 pm   Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!

Well the way you guys talk about a deck of cards, it sounds confusing. Okay, I thought about it and how does this sound:

Quote:
var num1 : real
var num2 : real
var num3 : real

put "Type down your number: "..
get num1,num2,num3

if num1 < num2 and num2 < num3 then
put num1 and num2
else
put num2 and num3
end if

Something like that?
Insectoid

Posted: Mon Nov 17, 2014 1:13 pm   Post subject: RE:I NEED HELP WITH 4.2 Practice Question 11!

That's very close, you're just messing up the syntax and not covering all cases.

Let's do this step by step.

Let's say you have 3 numbers. Can you find and print the biggest number?
Tony

Posted: Mon Nov 17, 2014 1:16 pm   Post subject: Re: I NEED HELP WITH 4.2 Practice Question 11!

Try it out with some numbers you've suggested before.
master-awesome @ Sat Nov 15, 2014 11:11 am wrote:

Quote:
5
8
2

First, read through the program yourself and decide on what the program will output as a result. To be very clear -- think about what the code, as is, will produce, not necessarily what the assignment says it should (it's okay for this answer to be different, we just want to understand the current code really well). Once you have this answer written down, run the program with the same input, and note the difference in output, if any. If you and the computer disagree on the output, then some detail has been missed.

Finding such details move you closer to better understanding exactly what is going on, and makes it easier to move forward.

It could also help to start with smaller problems. E.g., output only 1 number (instead of all 3) -- the smallest number.

In fact, to get us started, lets try this exercise:
Quote:

Given 3 numbers -- 5, 8, 2 -- what is the smallest number? Why is it the smallest?

Edit: to keep consistent with Insectoid, I will also accept "what is the biggest number" with the same followup question of why is it the biggest?

And because OP hasn't been answering the leading questions before, I propose not giving out any further help until the the above why? question is answered. It might seem very silly, but it's very important to be able to actually put that answer in words.
Tony's programming blog. DWITE - a programming contest.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: