Question:
Hi There.... Wt the proplem whit this program??PLEASE HELP ME!!?
?
2009-08-18 11:36:17 UTC
include
using namespace std;
int main ()
{
int arr[100], num, sum=0, size=0;

cout<<"Enter an integer: ";
cin>>num;

if (num < 0) num*=-1;

while (num != -999 && size < 100)
{
arr[size]=num;
size++;
cin>>num;

for (int j=1; j {
for (int i=0; i {
if (arr[i]>arr[i+1])
{
int temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}

int cont=1;
for (int i=1; i<100; i++)
{
if (arr[i-1]=arr[i])
{
cout< cont=1;
}
else
{
cont++;
}

cout< }
}
return 0;
}

thanx,
buy :)
Three answers:
?
2009-08-18 11:49:58 UTC
You need to state what the actual problem is. Does it compile OK ? If not, what are the error/warning messages ? If it does compile without errors/warnings then what happens when you run it ?



One obvious problem is that you force all your input numbers to be positive so the user can never enter -999 to terminate input, but I'm guess there may be other problems too.
tbshmkr
2009-08-18 12:39:07 UTC
What is wrong? Errors? Program not performing as expected?

=

Initialize num

- int arr[100], num, sum=0, size=0;

=

Nonsensical test

- while (num != -999 && size < 100)

- - ANY negative num is made positive before the test

- - - if (num < 0) num*=-1;
2009-08-18 11:47:33 UTC
while (num != -999 && size < 100) -- you did not initialize size


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...