reading numbers

I've work on this problem for 5 hours now and I can only make it work halfway. this is the question
Read a 4 character number. Output the result in in the following
format, input = 9873
3 ***
7 *******
8 ********
9 *********

If one of the numbers is not a digit, then put a ? mark
input = 98a3
3 ***
a ?
8 ********
9 *********

and this is what I have so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  #include <iostream>
using namespace std;

int main(int argc, char** argv) {
//Declare Variables 
    int number [4];
    int output=0;
    
    for(int i=0; i<4; i++)
    {
        cout<<"Please enter 4 numbers: "<<i+1<<endl;
        cin>>output;
        number[i]=output;
    
    }
    for(int c=0; c<4;c++)
    {
        
        for(int f=0; f<number[c];f++)
        {
            cout<<"*";
        }
        cout<<endl;
    }
  

return 0;
}


any ideas how to finish this??
Perhaps enter the data as a string not as a number array as you indicate it can have alphabetic characters as well. Then go through the string array to check isDigit in which case print '*' else print '?'
Last edited on
change to
1
2
    char number [4];
    char output=0;


Then google ascii characters and find the value for numbers 1-9

should get you on the right path

closed account (48T7M4Gy)
See: http://www.cplusplus.com/reference/cctype/isalpha/?kw=isalpha

There is also an associated function that will test for numbers ...
how do you do the ascii numbers? like where do you plug them in into?
I'm just missing how to arrange them in order
for example if I plug in 3 4 5 2 I get
***
****
*****
**
and what I want to get is
**
***
****
*****
closed account (48T7M4Gy)
Instead of c= 0 to 4, try c = 4 to 0
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <iostream>
  
  int main(int argc, char** argv)
  {
    //Declare variable 
    char number [4];
    
    for( int i = 0; i < 4; i++ )
    {
        std::cout << "Please enter 4 numbers: " << i + 1 << std::endl;
        std::cin >> number[i];
    }
    
    for( int i = 0; i < 4; i++ )
    {
        if ( isalpha( number[i]) )
            std::cout << '?';
        else
            for (int j = 0; j < number[i] - '0'; j++ )
                std::cout << '*';
        
        std::cout << std::endl;
    }
    
    return 0;
}
closed account (48T7M4Gy)
OOps, I misunderstood. You have to sort the input.
Topic archived. No new replies allowed.