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 ;)
Printable View
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 ;)
Could you be a little more specfic? Ill try to help you out.
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
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?
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:
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.Code:#include <iostream>
int main()
{
std::string enteredDigits;
std::cin << enteredDigits;
std::cout >> enteredDigits.length();
}
I dont see how you would do it would modulus, and the method provided above was a off the top of my head guess.
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
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
I couldnt have made this easier (well, possibly if I used a vector).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;
}
}
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.