Plz help stuck

This is a discussion on Plz help stuck within the C++ Programming forums, part of the General Programming Boards category; K hey all this is my first post... Plz help me i am stuck i can not figure out a ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    57

    Plz help stuck

    K hey all this is my first post...
    Plz help me i am stuck i can not figure out a way to get it to count the number of single numbers i enter is there a way..
    I thought mabie soemthign to do with modules or powers
    THnkas

  2. #2
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Could you be a little more specfic? Ill try to help you out.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    57
    hmm something like
    K fine i am tottaly stuck.
    here it goes i need for example:

    enter a number 1234
    1
    2
    3
    4

    I think i am pretty sure how to do it with modules but i need to know who many modules and hwo many times to loop blah
    Thanks

  4. #4
    Registered User
    Join Date
    Nov 2004
    Posts
    69
    Still not specific, at least not for me :/. But my guess is that you want it to split each number out of the string that contains "1234", and echo each one--one by one? Is that right?

  5. #5
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    He wants to count the number of digits entered through cin.

    It would have to be a digit, and not an integer (unless specified 1-9) becuase the way you're doing it you cant tell if its 12 and 3, or 1 and 23.

    Here:

    Code:
    #include <iostream>
    
    int main()
    {
    std::string enteredDigits;
    
    std::cin << enteredDigits;
    
    std::cout >> enteredDigits.length();
    
    
    }
    That was based on your first post, on your second post I would guess you want the digits split up (like the last poster said), in which case you'd probably convert it to an int, then assign make an array of ints, the length would be the enteredDigits.length() and you would assign the number to each one. Then you'd have to divide by 1*pow(1, enteredDigits.length() - 1) for the first one, and truncate; for the second one 0.1*pow(1, static_cast<float>enteredDigits.length() - 1), and truncate; then 0.01.. and so on.

    I dont see how you would do it would modulus, and the method provided above was a off the top of my head guess.
    Last edited by Dae; 09-26-2005 at 10:14 PM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    57
    K srry everyone for confusion.
    I have to use long
    get person to type almost any number bellow 64 bit
    then it needs to spread it on each line
    so exaple:
    please enter number : 25798345
    2
    5
    7
    9
    8
    3
    4
    5

    something like this
    thanks guys srry for cinfusion

  7. #7
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    I think the method I posted in the previous post might work with some modifications.. What it does is takes your input 123456, converts it to an int. So we have int 123456. Then take an array of 6 ints, assign 123456 to each one. For the first divide 123456 by 1 * (10^5) = 1.23456, truncate at 1 digit, leaving 1. Then do so for the next and the next, and you have your digits.

    5 comes from the string length - 1, and 10 is used to locate the digit each is on and bring it into scientific notation.

    convert string to int: http://www.cplusplus.com/ref/cstdlib/atol.html

    Code:
    #include <iostream>
    #include <cmath> //pow function
    
    int main()
    {
      int arrayofInts[6];
      int i;
      double j;
    
      for(i = 1, j = 0; i <= STRING.length(); ++i, j / 10.0) {
        arrayofInts[i] = THE INT FROM ATOL;
        arrayofInts[i] = arrayofInts[i] / j * (pow(1, STRING.length() - 1));
        /*truncate the number here, search google for how, e.g.
    http://64.233.187.104/search?q=cache:IrdQyaxKWjQJ:thechaosrift.com/phpBB2/viewtopic.php%3Ft
    %3D148%26sid%3D540d99bfffd51fdd3cabd24bb2d2aaa6+
    truncate+int+cplusplus.com&hl=en&client=firefox-a */
        std::cout << arrayofInts[i] << std::endl;
      }
    
    }
    I couldnt have made this easier (well, possibly if I used a vector).
    Last edited by Dae; 09-26-2005 at 10:29 PM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  8. #8
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Hey, just logged explain the easier way.

    Theres probably a way to iterate through a string 1 character at a time, and print that. That would be quick, easy and efficient. Since you dont need the digits to be integers (because you arent performing operations like add and subtract, and even if you were itd prob be easier to convert it at this stage also). So I would look up a way to either 1) iterate (go through) a string 1 character at a time, or 2) convert a string to a character, and then just iterate through the c-style string (e.g. a for loop going through acharString[i]).

    To read about iterating (under 'begin and end'), and string functions: http://www.msoe.edu/eecs/cese/resources/stl/string.htm

    That really would be the best way to solve this problem.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. Replies: 6
    Last Post: 10-23-2006, 07:22 PM
  3. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM
  4. I'm stuck with function, help plz
    By playboy1620 in forum C Programming
    Replies: 7
    Last Post: 03-27-2002, 07:23 AM
  5. i am really stuck, i need hlp plz
    By matheo917 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2001, 10:56 AM

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