Thread: where have i gone wrong?

1. where have i gone wrong?

Code:
```#include <iostream.h>

int main()

{
int number1;
int number2;
int stonum;
int count=0;
int num1;
int num2=1;

cout<<"Enter one single-digit number: ";
cin>>number1;
cout<<"Enter one single-digit number: ";
cin>>number2;

cout<<endl;
cout<<number1<<" "<<number2;

while (((number1)!=(num1))&&((number2)!=(num2)))
{
if (count<1)
{
num1=number1;
num2=number2;
}

count++;
stonum=((num1+num2)%10);
cout<<" "<<stonum;

number1=number2;
number2=stonum;

}

cout<<endl;

return (0);
}```

2. What errors do you get? I took a quick look through your code, but I couldn't find any syntax errors.

3. the program compiles just fine... its just that the while loop executes forever.

what is this program trying to accomplish, and what do YOU think the problem is?

4. Uhhnnn, you don't know what your program does? Well, I tried and compiled it and it print outs the sum of the two numbers you inputed modulo 10 (which is the same as the last number of the sum). At some numbers, it quits. Otherwise, it keeps on printing forever...

5. ok here is where i need help

ok this program is based on the number theory... it is know as the necklace program...

this is how it works

enter first number: 1
enter second number: 8

then we add 1+8= 9 then we add 8+9=17 and then removing the 1 resulting in the number 7 the next step is then to do 9+7=16 wich becomes 6 and so on until the necklace closes by repeating the beginning 1,8

1,8,9,7,6,3,9,2,1,3,4,7,1,8

plz help me!

6. If I'm understand what you're trying to do, it may not always work because % 10 gets stuck when num1 + num 2 is less than ten. 5 % 10 = 5, etc. I may be confused, though. It happens often enough.

5%10=5

8. well i have fixed some of my problem... it not generates most of the numbers... about 3/4 can anyone help?

Code:
```#include <iostream.h>

int main()

{
int number1;
int number2;
int stonum;
int count=0;
int num1;
int num2=1;

cout<<"Enter one single-digit number: ";
cin>>number1;
cout<<"Enter one single-digit number: ";
cin>>number2;

cout<<endl;
cout<<number1<<" "<<number2;

while (((number1)!=(num1))&&((number2)!=(num2)))
{
if (count<1)
{
num1=number1;
num2=number2;
}

count++;
stonum=((num1+num2)%10);
cout<<" "<<stonum;

num1=num2;
num2=stonum;

}
cout<<endl;
return (0);
}```

9. Originally posted by Unregistered

5%10=5
That's what I said