Thread: Help with the program

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    5

    Help with the program


    I need to modify the program so that will show the number of transformation that are made.

    Example:
    if i enter 712 it gave me the transformed number witch is 1, but i want to show me the number of transformation to, witch is 3.
    712->10->1.

    Code:
    #include <stdio.h>
    
    int main()
    {
    int input;
    printf ("Enter a number \n ");
    scanf ("%d", &input);
    int digit = 0;
    while (1)
    {
    if ( (input % 10 > 0) || (input /10 > 0) )
    {
    digit += input % 10;
    input /= 10;
    } else if ( digit > 9 )
    {
    input = digit;
    digit = 0;
    }
    else
    {
    break;
    }
    }
    printf("Your input is condensed to %d \n\n", digit);
    return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So you're saying that each time the loop runs you want to ... count? I wonder how you could do that.


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

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    it must be a simple thing to do it but i don't know how. the first operation is entering the number second and third are the calculations but i don't know how to write it to show me that.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Yeah, "simple" because you just copy/pasted your code from C program for condensing the given numbers into a single number

    I mean, if you has actually written any code yourself, and understood what say line 13 was doing, then writing something to add 1 to a counter would be so damn obvious it wouldn't even need to be asked.

    Just drop the course already, if this is your entire plan for getting through the course.

    If you've been copy/pasting homework up to now, you may as well just drop it now - you're already too far behind to make up the lost ground.

    You have absolutely no idea how much harder this is going to get.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    5
    its just my second week on a course and only 5th class .and i tried with incrementing the counter but it didn't work. and thanks for showing me from where my college knew it how to write the program and he was saying that he wrote it by himself.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > where my college knew it how to write the program and he was saying that he wrote it by himself.
    Great, so your tutor is copy/pasting code from the web as well.
    Talk about the blind leading the ignorant.

    > and i tried with incrementing the counter but it didn't work
    So post it already!
    That way, we can tell whether you're "way off base" or "really close" and advise you accordingly.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help converting array program to link list program
    By hsmith1976 in forum C++ Programming
    Replies: 0
    Last Post: 02-14-2010, 09:50 PM
  2. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  3. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  4. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  5. How To Make The Program Installed In Program Files Folder?
    By javacvb in forum Windows Programming
    Replies: 4
    Last Post: 11-05-2003, 05:33 PM

Tags for this Thread