Thread: Simple help. Breaking up "abc"

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    5

    Simple help. Breaking up "abc"

    Well its been the whole summer since I have programmed and I'm a little rusty. Also, my CS teacher from last semester did not teach me this, and my CS teacher this semester already expects me to know it.

    I simply need the equation to get 'b' out of 'abc'

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	int abc, a, b, c;
    	
    	cout << "Cameron Burton - CS 1362 - Lab 2" << endl;
    
    	for(abc=100;abc<=999;abc++)
    	{
    		a=abc/100;
    		b=?????;
    		c=abc%10;
    		
    		if(a+b+c == abc)
    		{
    			cout << abc << endl;	
    		}
    	}
    return 0;
    }

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Well if you know that division takes the digits off the front and modulus takes the digits off the back...

    Have you ever peeled a fruit?

    Oh and addition of integers isn't concatenation of integers, there for (9+9+9 != 999). Got it?
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    Well I have tried this...
    Code:
    for(abc=100;abc<=999;abc++)
    	{
    		a=abc/100;
    		ab=abc/10;
    		b=ab%10;
    		c=abc%10;
    		
    		if(a+b+c == abc)
    		{
    			cout << abc << endl;	
    		}
    	}
    but it still yields no results. and just by doing math in my head, I know that 1+2+3 is equal to 1*2*3. So there has to be some output.

    EDIT: Ok i saw your edit. Thats how my CS teacher wrote it on the board. So I don't know if he's lost his mind or what, but I know 9+9+9 != 999 What I'm trying to do is find all numbers that a+b+c == a*b*c
    But to do that I need to single out 'b' like I have already done with 'a' and 'c'.
    Last edited by SoBlue; 09-07-2006 at 03:51 PM.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Yeah, but that's not what you're comparing. You're comparing a+b+c to abc -- that is, you'd be comparing 1+2+3 (6) to 123, and 6 != 123.

    It will never print anything, because abc = 100a + 10b + c.

    100a + 10b + c = a + b + c is the same as 99a + 9b = 0.

    Because a is a positive number, and b cannot be negative, that equation has no solution.

    If you want to compare a + b + c and a * b * c you'd need to actually code that.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    5
    Ok. Thanks Cat and Sly, thanks alot. My teacher wrote it on the board as a+b+c == abc. I guess he assumed we would know to change 'abc' to 'a*b*c'.

    When it comes to programming with me, it's always something easy I miss. I'll write the hardest part of the code and always miss something. lol

    Thanks again.

  6. #6
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Also, my CS teacher from last semester did not teach me this...
    Don't expect them to "teach" you everything! There's a lot to C++ and they can't cover everything. Well... I guess you could cover most of the C++ standard in two college-level semester classes.

    Well its been the whole summer since I have programmed and I'm a little rusty.
    Yeah, even if they could teach you everything, you're not going to remember it all. Professional programmers always keep their reference books (and their online references) handy.

    IMHO taking a class is the best way to learn*, but you need to supplement that with books (at some point, probably some reference books in addition to your textbook), online references, online tutorials, and this-here forum!


    * I think most people here are learning on their own. But, most of the people with the "good answers" have taken programming classes. Many of these people are professional programmers with CS degrees. (I've never taken a C++ class, but I've taken classes in other programming languages.)

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Code:
    b=abc/10-a*10;
    Last edited by maxorator; 09-08-2006 at 11:42 AM.

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I don't understand what you mean. Do you want to receive an input string (char array)?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  4. Need help with simple data types
    By partnole in forum C++ Programming
    Replies: 1
    Last Post: 10-03-2001, 08:36 AM
  5. Linker errors with simple static library
    By Dang in forum Windows Programming
    Replies: 5
    Last Post: 09-08-2001, 09:38 AM