a c++ program

hi everyone;
i want a help immidietly
in this program i wanna give a 3digits num and the program show * as the number of digits. like
352
***
*****
**
Can't do your own homework or even try?

here are things to consider:
1. Ouput/Input
2. Loops
ex:
1
2
3
4
cout << "Can you do your homework?<y/n> " << flush;
cin >> answer;

for(int i = 0; i<9999999; i++) cout << "Maybe now I can!" << endl;
Lol @ giblit, nice piece of code.
closed account (3qX21hU5)
Use stringstreams to convert the integer to a string then use the strings size() member function to print out the correct number of "*"'s in a for loop.

Here is a example of this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <sstream>
#include <iostream>

using namespace std;

int main()
{
    int userNumber;
    cin >> userNumber;

    ostringstream convert;
    convert << userNumber;

    string stringNumber = convert.str();

    for (auto i = 0; i != stringNumber.size(); ++i)
        cout << "*";
}
@giblit LOL
@zereo why would you declare i as auto? What if the user inputs a letter like 'A'? And wouldn't it be easier to just do a loop like for(unsigned int i = 0; i<userNumber; i++) cout << "*"; and that would only make it so if the user inputs one number it will work.
heres another hint
1
2
3
4
5
6
7
8
cout << "size?" << flush;
cin >> size;
unsigned int i = 0;
do {
cout << "number: " << flush;
cin >> num[i];
i++;
} while(i < size);


I think the op can figure the rest out on his own though.
closed account (3qX21hU5)
Opps misunderstood his question, for some reason I was thinking he wanted each digit in the number converted into a asterisk (IE 123 would turn into "***").

Instead he wanted each digit of the number to output that many asterisks on its own line (I think).

So if the user entered the number 431 it would output something like this

****
***
*

Atleast that is how I understand the question now.
Last edited on
Well if you look at what he said he inputs 3, 5, & 2 and he gets an output of ***, *****, & **;
and what would be the purpose to find out how many digits are in a number? The number is how many asterisks there are and he needs to input multiple numbers not just one. What your code is doing is if the user inputs "28" it will print out "**" instead of "**" next line "********" if they input it as two different numbers or "****************************" if they input it as one number.
but I guess technically after looking at his post we are both wrong.
he wants to input 3 numbers at one time eg 352 and it print out "***" "*****" "**"
which would be something like
input as a string, turn each character into a number then loop for each number and after each loop print a blank line.
not going to post the code up though because I think he can figure it out.
yeah wasn't trying to be mean to you was just trying to say that =p and I don't think auto even works in c++ at least when ever I tried to use auto it doesn't work especially if I try and declare an int with auto that's why I mentioned anything
.... I don't think auto even works in c++ at least when ever I tried to use auto it doesn't work especially if I try and declare an int with auto .....


I can tell you that auto does work - can you imagine a language with a keyword that doesn't work?
well it does work sorry..but I always get an 'warning' if I try and use declare a variable as auto
1
2
auto nums;
auto int nums2;

and I always thought if you just declared it as int it is an auto.
[quote]warning: 'auto' will change meaning in C++0x; please remove it
closed account (3qX21hU5)
Its because you are not using a C++11 enabled compiler... Also you wouldn't declare auto int num2;.

What auto means is it will be the compilers task to find the correct type to hold that variable. Usually it is not need and shouldn't be used for common types like int, double, string ect.

Though I do use it for longer types like
1
2
string::size_type, vector<int>::iterator,
vector<string>::size_type


All them goodies.

Also I believe the OP mention that he only enters one number not more then one and then it outputs each digits of that number in asterisks on separate lines.

But who knows he gave a really short explanation to work with so we both could be wrong.
thanks
thanks
thanks
thanks
thanks
thanksthanks
thanks
thanksthanks
thanks
thanksthanks
thanks
thanks
............................................................
Topic archived. No new replies allowed.