difficult(4 me) mathematics program

This is a discussion on difficult(4 me) mathematics program within the C++ Programming forums, part of the General Programming Boards category; ok this program is based on the number theory... it is know as the necklace program... i have tried every ...

  1. #1
    Unregistered
    Guest

    difficult(4 me) mathematics program

    ok this program is based on the number theory... it is know as the necklace program... i have tried every single way i can think of and am seeking some help

    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! i repeat im not asking for freebies... i have worked on this a long time and am getting no-where

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Code:
    int main(void)
    {
    
    short int num1;
    short int num2;
    short int added;
    short int temp;
    
    cout << "Enter first number->";
    cin >> num1;
    cout << "Enter another number->";
    cin >> num2;
    
    do { 
    	cout << "\n\n";
    	added = num1 + num2;
    	cout << added << "\n";
    	added = num2 + (++num2)
    	cout << added << "\n";]
    
    	if (added % 10)
    	{
    		for (short int i = 0; i < 10; i++)
    		{
    			if (added % 10)
    			{
    				temp = added--;
    			} else {
    
    				added -= temp;
    				break;
    			}
    		}
    	} else {
    
    		added -= temp;
    	}
    	cout << added << "\n";
    	if (added != num2)
    	{
    		added = added + (++num2);
    	}
    } while (added != num2);
    
    cout << "It's almost like magic!\n";
    cin >> num2;    // to pause program;
    return 0;
    
    }

    Remember, I'm not perfect, and I didn't test this code
    Last edited by Dual-Catfish; 02-27-2002 at 06:35 PM.

  3. #3
    ˇAmo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Do your own hw. Post your code and then we'll help u with problems.

  4. #4
    Unregistered
    Guest
    Originally posted by golfinguy4
    Do your own hw. Post your code and then we'll help u with problems.
    ok dude this is not a whinny help me do your homework post ok you wanna see my code? fine i will post it! keep in mind its falling apart i was in the process of tryin something new...

    Code:
    #include <iostream.h>
    
    int main()
    
    {
    	int number1;
    	int number2;
    	
    	cout<<"Enter one single-digit number: ";
    	cin>>number1;
    	cout<<"Enter one single-digit number: ";
    	cin>>number2;
    	
    	cout<<endl;
    	cout<<number1<<number2;
    		
    	int stonum1=1;
    	int stonum2=8;
    
    	while (((number1)!=(stonum2))&&((number2)!=(stonum1)))
    	{
    		stonum2=stonum1;
    		stonum1=((number1+number2)%10);
    		cout<<stonum1;
    	}
    
    	cout<<endl;
    	
    	return (0);
    }
    you happy now goldfinger?

    many props to dual-catfish i will analyze your example and try to implement it into what i was working for thx dude!

  5. #5
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    No problem; I just hope I understood what you were asking. With a minimal amount of tinkering you should have it.

    Did the first 2 numbers have to be 1 and 8? Or could they be anything?

  6. #6
    Unregistered
    Guest
    the first two numbers are user inputed... well ill keep working on this once i get back to school i have too much physics work tnight

  7. #7
    :)
    Guest
    that is an interesting problem... weird how math works

  8. #8
    Unregistered
    Guest
    Check this.

    #include <iostream.h>

    int main()

    {
    int number1;
    int number2;

    bool b1,b2;

    b1=b2=false;

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

    cout<<endl;
    cout<<number1<<','<<number2;

    int stonum1=number1;
    int stonum2=number2;
    int stonum;

    while (b1!=true||b2!=true)
    {
    stonum=(stonum1+stonum2)%10;
    cout<<','<<stonum;
    stonum1=stonum2;
    stonum2=stonum;
    if(b1!=true&&stonum==number1)
    {
    b1=true;
    continue;
    }

    if(stonum==number2)
    {
    b2=true;
    continue;
    }
    b1=b2=false;
    }
    cout<<endl;
    return 0;
    }

  9. #9
    Registered User
    Join Date
    Nov 2001
    Posts
    8

    Hello

    Stop using people to do your homework do it yourself this forum is not intended for people to do everything for you, but only for people to give tips.

  10. #10
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > Stop using people to do your homework do it yourself this forum is not intended for people to do everything for you, but only for people to give tips.

    Chill out. They did post their code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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