where have i gone wrong?

This is a discussion on where have i gone wrong? within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> int main() { int number1; int number2; int stonum; int count=0; int num1; int num2=1; cout<<"Enter one ...

  1. #1
    Unregistered
    Guest

    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. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    What errors do you get? I took a quick look through your code, but I couldn't find any syntax errors.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    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. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Unregistered
    Guest
    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. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    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.

  7. #7
    Unregistered
    Guest
    your confused....

    5%10=5

  8. #8
    Unregistered
    Guest
    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. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    Originally posted by Unregistered
    your confused....

    5%10=5
    That's what I said

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 04:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21