Results 1 to 6 of 6

Thread: [RESOLVED] C++ questions

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2006
    Posts
    384

    Resolved [RESOLVED] C++ questions

    Hello, I have the following homework exercies which I couldn't resolve, can anybody tell me how to do them, Thanks in advance..

    QUESTION1

    Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits, example ( if he entered 3456 then it should print 3 4 5 6 and also if he entered 23454566 etc).

    QUESTION2

    Write a program that prompts the user to input an intefer then outputs the number with the digits reversed as: 12345 ---> 54321 and also 400 --> 004.



    Thanks for the help,
    zeid

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771

    Re: C++ questions

    Since this is a homework assignment I will not give you an actuall implementation.

    Question1:
    There are two ways to solve this, either read a number, and extract digits, etc.
    But do you really need a number? In this case reading a string should be enough.

    Question2:
    Same thing, don't interpret this as a number question, but as a string question.


    It may be the case that you are actually supposed to use numbers instead of strings, in that case the questions are worded incorrectly, because they also allow the (simpler) string implementation. In fact, reversing "400" to get "004" is only possible with strings, because as a number it would be just "4".

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2006
    Posts
    384

    Re: C++ questions

    thank u, but i'm completely new to c++ so can u please show me the code of doing it. or can anyone else help me with it..

    Thanks again,
    zeid

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: C++ questions

    You can use the modulo operator (%) to split numbers into their parts. Now grab your C++ textbook (you do have such a thing, right?) and solve the problem.

    Because I'm in a good mood, here's some pseudo-code to do the first part of the first exercise.
    Code:
    number = read number from user;
    while(number > 0) {
      digit = number % 10;
      number = number / 10;
    
      print digit;
    }
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157

    Re: C++ questions

    Hi CornedBee,

    Isn't what you wrote 'pseudo - pseudo code'?

    ChuckB
    I learn Robotics, Electronics and Game Programming at http://www.gameinstitute.com

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: C++ questions

    There's no standard for pseudo-code. Mine always looks like this.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width