Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Find Number of Equal Consecutive Numbers
Author Message
CtrlAltDelicious

Posted: Tue Jun 06, 2017 8:29 am   Post subject: Find Number of Equal Consecutive Numbers

What is it you are trying to achieve?

Write a program that prompts the user for a sequence of integers, using zero as the end of input. The program should count the number of times that two consecutive values are equal. For example, if the inputs is 3 6 7 7 4 4 4 6 0 then the program should determine that there are three cases in which consecutive values are equal. (use “if” statement inside “while” loop)

Describe what you have tried to solve this problem

Have a previous number integer that will later be used in an "if" statement, to determine if the current & last number entered by the user are equal.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)

var integer1 : int
var integer2 : int
var counter : int
counter := 0
var previous : int

get integer1

loop

get integer2
exit when integer2 = 0

if integer1 = integer2 then
counter := counter + 1
end if

previous := integer2

if previous = integer2 then
counter := counter + 1
end if

previous := integer2

end loop

% Display Final result
put ""
put "There is/are ", counter, " case(s) in which the numbers you've " ..
put "entered are equal."

Please specify what version of Turing you are using

Turing 4.1.1
Sponsor
Sponsor

Insectoid

Posted: Tue Jun 06, 2017 9:42 am   Post subject: RE:Find Number of Equal Consecutive Numbers

What part are you having trouble with?
CtrlAltDelicious

Posted: Tue Jun 06, 2017 7:41 pm   Post subject: Re: Find Number of Equal Consecutive Numbers

So far, I've developed a rough idea on how I should use the variables (previous integer & current integer), but don't actually know how to use them properly in a loop, if that makes sense.
Insectoid

Posted: Wed Jun 07, 2017 4:14 pm   Post subject: RE:Find Number of Equal Consecutive Numbers

You're on the right track. Here's a quick hint: you can do away with your previous variable and use your integer1 variable for both jobs.
CtrlAltDelicious

Posted: Fri Jun 16, 2017 8:49 am   Post subject: Re: Find Number of Equal Consecutive Numbers

Sorry, could you clarify on what you meant by both integers being able to do?
CtrlAltDelicious

Posted: Tue Jun 20, 2017 7:42 am   Post subject: Re: Find Number of Equal Consecutive Numbers

I'm stuck on how I should use the previous integer variable..
Insectoid

Posted: Tue Jun 20, 2017 1:14 pm   Post subject: RE:Find Number of Equal Consecutive Numbers

You're only ever checking two numbers against each other, so you only need two variables, right? One for the first number and one for the second. When another number is entered, the first can be discarded, the second becomes the first, and the new number is now the second. Now you can compare them exactly the same way you did the first two numbers! Repeat until there are no more numbers.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 7 Posts ]
 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: