Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Math Problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jurica




PostPosted: Thu Nov 06, 2008 4:01 pm   Post subject: Math Problem

I have a problem with this Question, I don't need the answer, just need the code.

Question: Write a progem that will ask for the Length and Width of a Rectangle. The program will then calculate the Area and Perimeter. Make sure your output is clear to the user and includes the user input.

Don't know the codes for Length, Width, and all that stuff, I have a book but doesn't show the coding for it.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Nov 06, 2008 4:08 pm   Post subject: RE:Math Problem

If your were solving this problem yourself, on paper (while showing every step), how would you do it?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Jurica




PostPosted: Thu Nov 06, 2008 4:10 pm   Post subject: Re: RE:Math Problem

Tony @ Thu Nov 06, 2008 4:08 pm wrote:
If your were solving this problem yourself, on paper (while showing every step), how would you do it?

I don't know, that's why I'm asking.
jernst




PostPosted: Thu Nov 06, 2008 4:25 pm   Post subject: Re: Math Problem

Maybe try breaking the problem up into small parts:

You will need to get the length and width from the user. So you will need variables for this, and a way to get it from the users....that part you will have to figure out with your book, or through code online.

You will also need to know how to use the length and width to calculate the area and perimeter. You will need some kind of math formula for this which you should know, or could easily find with google / wikipedia.

Then after you figure out the answers you will need to know how to show it to the user. You will need to find how to output information as well. It will likely be similar to the code for getting the information from the users.
Jurica




PostPosted: Thu Nov 06, 2008 7:46 pm   Post subject: Re: Math Problem

jernst @ Thu Nov 06, 2008 4:25 pm wrote:
Maybe try breaking the problem up into small parts:

You will need to get the length and width from the user. So you will need variables for this, and a way to get it from the users....that part you will have to figure out with your book, or through code online.

You will also need to know how to use the length and width to calculate the area and perimeter. You will need some kind of math formula for this which you should know, or could easily find with google / wikipedia.

Then after you figure out the answers you will need to know how to show it to the user. You will need to find how to output information as well. It will likely be similar to the code for getting the information from the users.

Okay, going to try to do it, thanks for your help.
sierius




PostPosted: Thu Nov 06, 2008 8:10 pm   Post subject: Re: Math Problem

Well, first start by doing what the question tells you

Quote:
Write a program which asks for the length and width of a rectangle

This can be written as (while assuming length and width are integers)
code:

var length, width : int
put "Please enter the length : "  ..
get length
put "Please enter the width : "  ..
get width


Well, you got the length and width stored.. but now what?

Time for some math. There are no widths and two lengths to account for
We know the perimeter of a rectangle can be expressed, where L represents length and W represents width ;
code:
P = 2L + 2W


The area? We know the area of a rectangle can be expressed as, the length of the x axis * the length of the y axis ;
code:
A = L*W


Then use the mathematical equation and add them to your program, and return to the user !
code:

var length, width : int
put "Please enter the length : "  ..
get length
put "Please enter the width : "  ..
get width
cls  %% this clears the screen
var perimeter := 2*length + 2*width
var area := length*width
put "The perimeter of your rectangle of the given values would be : ", perimeter, " units."
put "The area of your rectangle of the given values would be : ", area, "units squares."
Vertico




PostPosted: Thu Nov 06, 2008 8:27 pm   Post subject: Re: Math Problem

length is a predefined identifier, you will need to use something else for the variable name.

Also, doing the program for him is a little over board. Not to speak rude of him, but seeing all the threads he has started in the last few weeks, it does not seem like he has much interest in trying these things himself.
Jurica




PostPosted: Thu Nov 06, 2008 8:54 pm   Post subject: Re: Math Problem

Vertico @ Thu Nov 06, 2008 8:27 pm wrote:
length is a predefined identifier, you will need to use something else for the variable name.

Also, doing the program for him is a little over board. Not to speak rude of him, but seeing all the threads he has started in the last few weeks, it does not seem like he has much interest in trying these things himself.

I just finished this, and this time it was all me, just some of the guys gave me a way to start it, that was just all I needed. And don't worry you're not speaking rude, I've started many threads of asking help. Just found this website like a week ago, and needed lots of help with my Computer Science class. Didn't really have any interest for like the first couple of weeks, but now I'm serious.
Sponsor
Sponsor
Sponsor
sponsor
S_Grimm




PostPosted: Thu Nov 06, 2008 9:05 pm   Post subject: Re: Math Problem

Ok, first off, posting asking for the code is NOT asking for help. It's asking for US to do YOUR work for you. Second, copying and pasting the code IS NOT finishing it by yourself. When you post a topic asking for help, do one of two things

1) Post a copy of the code and ask where it is going wrong

or

2) Post asking your problem, how you've started to solve it, and if there is anyway to do it better.


DO NOT POST ASKING FOR US TO DO THE CODE FOR YOU. AS IN DO NOT POST LIKE THIS :

Quote:

I have a problem with this Question, I don't need the answer, just need the code.


Cheers.
A\V

edit: Sorry to anyone who is offended by this, but it needed to be said.
Tony




PostPosted: Thu Nov 06, 2008 9:24 pm   Post subject: Re: Math Problem

A\V @ Thu Nov 06, 2008 9:05 pm wrote:
it needed to be said.

It's also one of the forum rules. Please behave. I have a shortcut to a ban button, for others.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Clayton




PostPosted: Thu Nov 06, 2008 10:45 pm   Post subject: Re: Math Problem

Tony @ Thu Nov 06, 2008 9:24 pm wrote:
A\V @ Thu Nov 06, 2008 9:05 pm wrote:
it needed to be said.

It's also one of the forum rules. Please behave. I have a shortcut to a ban button, for others.
For quick reference: [The Rules]. I also have a shortercut to the ban button Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: