Thread: Conversion

  1. #1
    CyberMax8
    Guest

    Question Conversion

    Hey,

    Can somebody help me with a conversion program?

    This is what I need:

    1. Prompt a user for a number in BASE 10

    2. Prompt a user to enter the base to convert to

    3. Display the number in the requested base

    4. Prompt if they want to do it again, exit when answer is no

    Thanks,

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1. Prompt the board memebers for help on your homework.
    2. Beg and plead with them to do it all for you.
    3. Get angry when they don't do all of your home work for you.
    4. Crosspost and make multiple posts on the same topic.

    Thanks.

    Oh, no, wait, that's bad to do. Try this on insead:

    1. Try to figure this out yourself, giving it your best effort.
    2. When you're stuck, post your code attempt, using [code] [/code] tags.
    3. List any error messages you get, and list what the program is supposed to do, and what it is doing that it shouldn't be.
    4. Wait patiently for an answer, and don't corsspost or make multiple posts for the same issue.

    Thanks.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    If you are allowed to use it, strtol() will make your life easier.

    man strtol

  4. #4
    CyberMax8
    Guest
    Code:
    #include <stdio.h>
    
    void convert(int num, int base)
    {
    	int n;
    	
    	if (num == 0) 
    		return;
    	else {
    		convert(num / base, base);
    		
    		n = num - num / base * base;
    		if (n < 10)
    			printf("%d", n);
    		else
    			printf("%c", (65 + n - 10));
    	}
    }
    
    int main(void)
    {
    	int num, base;
    	char cont = 'y';
    
    	while (cont == 'y') {
    		printf ("Enter a decimal number to convert: ");
    		scanf ("%d", &num);
    		printf ("Enter the base to convert the number to: ");
    		scanf ("%d", &base);
    
    		convert(num, base);
    		printf("\n");
    		
    		printf ("Do you wish to convert again? ");
    		scanf ("%c %c", &cont, &cont);
    		printf ("\n");
    	}
    	
    	return 0;
    }
    gee....thanks for ALL the help there quzah.
    if ya ain't got nothing useful to say then don't say anything at all!

    and no, I don't expect others to do all my work for me, however sometimes if I'm stuck or running out of town I will turn to others for help, and will return the same.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by CyberMax8
    gee....thanks for ALL the help there quzah.
    if ya ain't got nothing useful to say then don't say anything at all!

    and no, I don't expect others to do all my work for me, however sometimes if I'm stuck or running out of town I will turn to others for help, and will return the same.
    CyberMax8, it's nothing personal, don't take it so. The problem was your original question, it looked like you had copied it straight from the homework assignment paper to this forum. This board has a policy regarding homework that says we won't do it all for you, but we will provide help when the requestor shows they're willing. Next time, just show you've made an effort, and point out which bit you're stuck on, and you'll get a better response. In case you don't realise, there are plenty of people out there who are all too willing to reap the benefits of our help and do no work of their own, but from your most recent post, I guess you're not one of them
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    CyberMax8
    Guest

    Smile To: Hammer

    Yes Hammer, my original post did seem as if though I wanted everything done for me, when I was really stuck on the "conversion" part, the modulo, char
    I guess it's something to keep in mind next time I post.

    My prob with quzah was I guess his wording or approach.

    I appreciate your "gentler" response.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by CyberMax8
    gee....thanks for ALL the help there quzah.
    if ya ain't got nothing useful to say then don't say anything at all!
    If you aren't going to read the rules of the forum, and if you aren't going to post your code, don't bother posting at all.

    Originally posted by CyberMax8
    and no, I don't expect others to do all my work for me, however sometimes if I'm stuck or running out of town I will turn to others for help, and will return the same.
    You don't expect others to do your work, however, sometimes you run out of town so you expect someone to do it for you? Can we say hypocritical?

    So let's recap:
    1. Post demands.
    2. Post no code.
    3. Post no specifics on what the problem is.
    4. Expect me to be a mind reader, telling you exactly what the problem is?
    [edit] I almost forgot the most important...
    5. Act surprised when the answer isn't given!
    [/edit]

    Quzah.
    Last edited by quzah; 11-20-2002 at 08:34 PM.
    Hope is the first step on the road to disappointment.

  8. #8
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > I appreciate your "gentler" response.
    Quzah has a point, and a very good one at that.
    More importantly, you should be extremely thankful that he isn't flat out ignoring you.

    Perhaps you should read "How to ask questions the smart way".
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  4. Do I have a scanf problem?
    By AQWst in forum C Programming
    Replies: 2
    Last Post: 11-26-2004, 06:18 PM
  5. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 09:44 PM