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

Username:   Password: 
 RegisterRegister   
 how to ask for 2 numbers, then the computer adds the numbers and give out the sum.
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cwlvc




PostPosted: Wed Jan 09, 2008 1:34 pm   Post subject: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

ok, i know what it is now. i need a program that allows to me ask 2 question on the run screen, then the computer adds the 2, and gives out the sum.

this is what i've got.

var num : int
put "enter a number between 1 and 5"
get num
put "the number you entered is", num


now how do i ask this question again?

when i copy and paste, they said i have an eror.

after, what do i do to let the computer add the sum, and say "the sum of the 2 numbers you entered is..."


then the computer should ask if this is what the viewer wanted. press 1 if it is, press 2 if it's not. if not, the program starts over again.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Jan 09, 2008 1:40 pm   Post subject: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

you should write down what errors you get.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
cwlvc




PostPosted: Wed Jan 09, 2008 1:43 pm   Post subject: Re: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Tony @ Wed Jan 09, 2008 1:40 pm wrote:
you should write down what errors you get.


when i type it twice, my error is here.

var num : int
put "enter a number between 1 and 5"
get num
put "the number you entered is", num

var num : int
put "enter a number between 1 and 5"
get num
put "the number you entered is", num

i think it's there.
ericfourfour




PostPosted: Wed Jan 09, 2008 1:50 pm   Post subject: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

You declared num twice. Remove the second declaration or change the variable names.
Tony




PostPosted: Wed Jan 09, 2008 2:35 pm   Post subject: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

if you are looking for two different numbers, chances you that you want two different variables to store their value.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
iluvchairs112




PostPosted: Wed Jan 09, 2008 4:04 pm   Post subject: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

you have

var num : int
put "enter a number between 1 and 5"
get num
put "the number you entered is", num

when you copy and paste this, change it to

var num2 : int
put "enter a number between 1 and 5"
get num2
put "the number you entered is", num2

you need to different variable names. you can't declare two different variables with the same name. to add it together you can create a third variable that adds the two numbers or just use "put" to write what the two numbers add to
shakin cookie




PostPosted: Wed Jan 09, 2008 4:08 pm   Post subject: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Turing:

var num : int
put "enter a number between 1 and 5"
get num
put "the number you entered is", num

var num2 : int
put "enter a number between 1 and 5"
get num2
put "the number you entered is", num2

%then, to add the two numbers:

put " You're first number, ", num, ", + you're second number, ", num2, " is ", num + num2

%You could also just output the sum without any string statements:

% put num " + ",num2," = ",num+num2. "



that would be the coding for also outputting the answer.
iluvchairs112




PostPosted: Wed Jan 09, 2008 4:14 pm   Post subject: Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

or you could make a third variable

var sum : int
sum := num + num2
put sum[/list][/quote][/list]
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Wed Jan 09, 2008 4:43 pm   Post subject: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

This is so unbelievably basic that it needs no explanation. Didn't your teacher go over this yet?
shakin cookie




PostPosted: Wed Jan 09, 2008 5:03 pm   Post subject: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

yes, you could do that, but he needs the most basic answer.

Ya, i'm in grade 9, and my teacher went over this the third class, so his teacher must be doing it completely different.
Zampano




PostPosted: Wed Jan 09, 2008 5:30 pm   Post subject: Re: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

shakin cookie @ Wed Jan 09, 2008 5:03 pm wrote:
yes, you could do that, but he needs the most basic answer.

Ya, i'm in grade 9, and my teacher went over this the third class, so his teacher must be doing it completely different.


Completely different? Is there anything one can do that doesn't in any way refer to such basic principles of programming but still teaches it?

I think some one has told you this before, but go over the basic things in the Turing Walkthrough and problems like these will become incredibly simple to you. Furthermore, if you run into problems, try and work something out on your self. If you tinkered with the code, you could easily have completed this on your own.
cwlvc




PostPosted: Wed Jan 09, 2008 5:50 pm   Post subject: Re: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

shakin cookie @ Wed Jan 09, 2008 5:03 pm wrote:
yes, you could do that, but he needs the most basic answer.

Ya, i'm in grade 9, and my teacher went over this the third class, so his teacher must be doing it completely different.


it's because this is not our main thing. we never really went over this. we just got a booklet, did the booklet in 3 days all by ourselfs, then we were doing something else.

it's a computer engineer class, so we build circuits, and made a joy stick.

but i'll have computer science next semester so i'll prabably learn all about this.
cwlvc




PostPosted: Wed Jan 09, 2008 5:53 pm   Post subject: Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

how do i add a space between "is" and the number?

cause right now, after i type in my number, it is saying "the number you entered is1"

and how do i add a blank line between my first and second.

right now, it's


"the number you entered is1
enter a number between 1 and 5"

i'm looking for some space between those 2
Tony




PostPosted: Wed Jan 09, 2008 5:55 pm   Post subject: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

for spaces, just add an extra space, so "the number you entered is "

to add an extra line, you can either output a blank like
code:

put ""

or use a special new-line character \n
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
cwlvc




PostPosted: Wed Jan 09, 2008 6:13 pm   Post subject: Re: RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Tony @ Wed Jan 09, 2008 5:55 pm wrote:
for spaces, just add an extra space, so "the number you entered is "

to add an extra line, you can either output a blank like
code:

put ""

or use a special new-line character \n


oh, thanks. i knew i should of tried to put a space in the " ". instead, i put like 1000 spaces outside of the quotes. Crying or Very sad
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 3  [ 34 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: