Computer Science Canada

how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Author:  cwlvc [ 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.

Author:  Tony [ 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.

Author:  cwlvc [ 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.

Author:  ericfourfour [ 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.

Author:  Tony [ 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.

Author:  iluvchairs112 [ 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

Author:  shakin cookie [ 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.

Author:  iluvchairs112 [ 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]

Author:  CodeMonkey2000 [ 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?

Author:  shakin cookie [ 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.

Author:  Zampano [ 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.

Author:  cwlvc [ 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.

Author:  cwlvc [ 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

Author:  Tony [ 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

Author:  cwlvc [ 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

Author:  cwlvc [ Wed Jan 09, 2008 6:25 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

and 1 last question, at the end, i need to ask the view if the answer is what they wanted. press 1 if yes, press 2 if no. if yes, it will be outputted to the parallel port on the 7-degit segment, if no, the system will start over.

does anyone know how to do that, or can tell me which one of the tutorials i should read to find out?

i think this is an infinite loop right?

Author:  cwlvc [ Wed Jan 09, 2008 6:33 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

well, i've read the loop and for loop tutorial. it said that i can have an "exit"

so i can tell the computer to only exit when 1 is pressed, which means it'll exit when people say yes and keep going if people press 2, which is no.

but when i say exit when people press 1, will the sum of the 2 number still be outputted to the parallel port and show on my 7-segment counter?



and i still don't knwo how to ask the viewer to "press 1 if this is what you wanted, press 2 if this is not what you wanted. if yes, it will be displayed, if no, it will start over"

Author:  cwlvc [ Wed Jan 09, 2008 8:12 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

so can any of you guys help me, or atleast tell me the tutorial that i have to read to find out what i need?

Author:  Sean [ Wed Jan 09, 2008 8:20 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

So.. You are right with the exit, when...

Turing:

exit when response = "1"


And to tell them to select it, put a put statement with your instruction on how to end and continue.

Author:  cwlvc [ Wed Jan 09, 2008 8:47 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Vilament @ Wed Jan 09, 2008 8:20 pm wrote:
So.. You are right with the exit, when...

Turing:

exit when response = "1"


And to tell them to select it, put a put statement with your instruction on how to end and continue.


lol, i did that. but what do i have to write so when they press 2 (which is that the answer is not what they wanted and they would like to start over"?

Author:  Sean [ Wed Jan 09, 2008 8:49 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Just add a cls at the end I believe, on a computer without Turing installed, going to check on other machine aswell.

Hopefully it is all in a loop.

Author:  Sean [ Wed Jan 09, 2008 8:59 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Need to write nothing for 2, just type 2 in since it doesn't equal 1 then it clears screen and re-does the loop.

Author:  cwlvc [ Wed Jan 09, 2008 9:12 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Vilament @ Wed Jan 09, 2008 8:59 pm wrote:
Need to write nothing for 2, just type 2 in since it doesn't equal 1 then it clears screen and re-does the loop.


oh, i think i know what your talking about. i'll try it.

and by the way, i like ur avatar, first i though when it got to damn, it wasn't finished, then i realized it was saying it don't give a damn. lol.

Author:  cwlvc [ Wed Jan 09, 2008 9:16 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

wait, this is not right.

when i use the exit thing, it said it needs to equal 1. but when i ask the question, it isn't adding nothing. the view just need to press 1 or 2.

this is what i've got.

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

put " "

var num2 : int
put "enter a number between 1 and 5 "
get num2
put "the number you entered is " , num2
put " "
var sum : int
sum := num + num2
put "the sum of the 2 numbers are ", sum

put"if this number what you wanted?"

exit when num = 1

end loop


after the sum part, i just need to ask a question, the view press 1 or 2, and the computer will work accordingly

Author:  iluvchairs112 [ Wed Jan 09, 2008 9:23 pm ]
Post subject:  RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

after
put"if this number what you wanted?"
you need a get statement. in the code you have written, you would want to "get" num
however you have num declared earlier. perhaps you might want to include a different variable. so you should declare a different variable, let's say x, earlier.

Author:  cwlvc [ Wed Jan 09, 2008 9:37 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

yay, i got it Very Happy

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

put " "

var num2 : int
put "enter a number between 1 and 5 "
get num2
put "the number you entered is " , num2
put " "
var sum : int
sum := num + num2
put "the sum of the 2 numbers are ", sum

put "if you want to exit, press 1, if you wanna redo it, press 2"
get ans
exit when ans = 1
cls
end loop

^just courious, but after the view say, yes, it is what we want, and press 1, and the program stops, will the sum(say the sum is 4) be put in the prarllel port and into my 7-segment counter? it's just a screen that'll show 4, or w.e. the sum is on a bread board.

Author:  cwlvc [ Wed Jan 09, 2008 10:14 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

iight, for my program above, and i ran it, it gave me this.

enter a number between 1 and 5
2
the number you entered is 2

enter a number between 1 and 5
3
the number you entered is 3

the sum of the 2 numbers are 5

if you want to exit, press 1, if you want to redo it, press 2"
1



iight, for the above part, how do i change the bolded part to something like 2 + 3 = 5. like, instead of just saying the sum of the 2 numbers are 5, i would like it to show the steps.

anyone know how to do that?

Author:  iluvchairs112 [ Thu Jan 10, 2008 6:34 am ]
Post subject:  RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

what do you mean show the steps??
the steps are fairly basic

Author:  Nick [ Thu Jan 10, 2008 7:20 am ]
Post subject:  RE:how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

you mean to actually display 2 + 3?

well the same way as you did with displaying the number

code:
put "The numbers are ",num," and ", num2,"together they are",num," + ",num2," = ",sum"

Author:  Sean [ Thu Jan 10, 2008 7:54 am ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Turing:

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

put " "

var num2 : int
put "enter a number between 1 and 5 "
get num2
put "the number you entered is " , num2
put " "
var sum : int
sum := num + num2
put "the sum of the 2 numbers are ", sum

put "if you want to exit, press 1, if you wanna redo it, press 2"
get ans
exit when ans = 1
cls
end loop


Instead of using a number for an exit, like 1 and 2 , you can make Yes or No as your User Responses.. Just changing your ans variable to a string and say..

Turing:

exit when ans (1) = "Y"


Also I suggest changing your number variables to reals. Because your adding can have decimals, integers are any positve or negative whole numbers, where real can be positive and negative, whole or decimal numbers.

Author:  cwlvc [ Thu Jan 10, 2008 5:44 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

i need HELP

i have written this program in class, i have done what the teacher asked us for. The program just adds two numbers and shows the answer.

BUT i need to add one thing i don't know HOW?
ok here is my story, , in computer engineering first we build a counter by using a 7 segment ship. after that i need to use the program below in order to show the sum of the answer of the cicuit or the ship. SO if the answer is 7. then on the 7 segment it will show the number 7.

basicly i don't know how to use parallelporting


so plz can anyone help me Confused

Author:  cwlvc [ Thu Jan 10, 2008 5:47 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

THE PROGRAM IS:


Turing:
loop

var variableName : int
var num,ans : int
     put "enter a number between 1 and 5 "
     get num
     cls
     put "the number you entered is " , num
    delay (1000)
      cls

var num2 : int
     put "enter a number between 1 and 4 "
     get num2
     cls
put "the number you entered is " , num2
delay (1000)
cls
 
var sum : int
     
     sum := num + num2
     put num," + ",num2," = ",sum
     delay (1000) 
     cls
     put "if you want to exit, press 1, if you wanna redo it, press 2" 
     get ans
     exit when ans = 1
cls


end loop

Author:  Sean [ Thu Jan 10, 2008 5:51 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

Please post it as a syntax, click more tages then syntax and between the quotes type Turing.

Author:  cwlvc [ Thu Jan 10, 2008 5:58 pm ]
Post subject:  Re: how to ask for 2 numbers, then the computer adds the numbers and give out the sum.

HOw do u put it in syntax


: