473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Input a sequence of integers and output omitting repeats

Write the statements, including loop, to read in a sequence of positive integers and display the sequence after deleting adjacent repeated values. Use negative integer to terminate the loop. For example, if the user enters the following sequence:

12 16 16 8 22 55 55 55 19 16 42 -1

the output will be

12 16 8 22 55 19 16 42

Pleas do help me with this problem..

this is my source code..

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int array_num[100];
  8.     int temp,index_array,breaker;
  9.     index_array = 0;
  10.     cout << "Enter your numbers : ";
  11.     do 
  12.     {
  13.         int input;
  14.         cin >> input;
  15.         input = breaker;
  16.         if (input != temp)
  17.         {
  18.            array_num[index_array] = input;
  19.            index_array++;
  20.            temp = input;
  21.         } 
  22.         else 
  23.         {
  24.            continue;
  25.         }
  26.     } while (breaker != -1);
  27.     int i;
  28.     for (int i = 0; i < index_array; i++)
  29.     {
  30.         cout << array_num[i];
  31.     }
  32.     char freeze;
  33.     cin >> freeze;
  34.  
  35. return 0 ;
  36. }
  37.  
Jul 15 '10 #1
2 2809
donbock
2,426 Expert 2GB
Presumably your program doesn't work. What is wrong? Do you get compiler errors? Do you get run-time errors? Does the program run but give the wrong answers?
Jul 15 '10 #2
hype261
207 100+
@puterialia90
I believe that your problem lies in this line of code...

input = breaker;

You have just lost the value that the user entered into the program and put in a trash value so it would be very hard input to equal temp.

It should be breaker = input;

Your loop is also poorly constructed because it will evaluate the negative ending number and add it to the end of the list.



Also you may want to look at this line of code. Depending upon what version of the C++ standard your compiler is using you may get a compilier error for duplicate declaration of the int i.


Expand|Select|Wrap|Line Numbers
  1. int i; 
  2.     for (int i = 0; i < index_array; i++) 
  3.     { 
  4.         cout << array_num[i]; 
  5.     } 
  6.  
Jul 15 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
9
by: Sudesh Sawant | last post by:
Hello, We have an application which communicates using remoting. There is a server which is a Windows Service. The server exposes an object which is a singleton. The client is a Web Application...
117
by: Peter Olcott | last post by:
www.halting-problem.com
0
by: James Griffiths | last post by:
Here is a report I've written about a printing problem that is being experienced by a particular company for whom I had developed a A97 system. After upgrading to Win XP and AXP, some printing...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
15
by: Martin Lang | last post by:
Hi All, Thanks for reading this :) I have a form A that consists of a main form A and a sub form A. In sub form A, I have a field which I can double click. Then, Main form B opens up with a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.