I can't tell what my instructor is asking for??

I can do this problem fine with MarkNumber(char [3]); but I'm not sure if that is what he means. Marknumber(char); will only read one digit, right?

1
2
3
4
5
6
7
8
Write a function MarkNumber(char) that takes an input character 
between 0 and 127 then outputs a string of numbers in the following form

Input     Output
0         0
9         0123456789
19        01234567890123456789
25        01234567890123456789012345
Last edited on
Maybe he means char in the sense of a one byte integer

http://www.cplusplus.com/doc/tutorial/variables/
Last edited on
I guess so...

I'm leaning toward turning this one in, but it reads in an integer and I'm not sure if that breaks the rules.

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

char MarkNumber (char);
int main(int argc, char** argv) {
    int n;
    cin>>n;
    MarkNumber(n);
    return 0;
}

char MarkNumber(char a)
{ 
    int i=0;
        while(a>=0)
        {         
         cout<<i;
         i++;
         a--;
                if(i==10){i=0;}
         
     }
}


I also wrote this, but it doesn't stop at 127.....

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42

#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;

char MarkNumber (char);
int main(int argc, char** argv) {


char MarkNumber[3];
cin>>MarkNumber;

int a;

ofstream myfile;
myfile.open ("example.dat");
myfile << MarkNumber;
myfile.close();
    
  ifstream is("example.dat");
  int input;
 
  is>>input;
   a=input;
   
     int i=0;
        while(a>=0)
        {         
            cout<<i;
            i++;
            a--;
                if(i==10)
                {
                    i=0;
                }
         
     }
 
    return 0;
}
ascii values go up to 127 and extended ascii values go to 255, and these integers are what's behind the char, so you just need one char like he said MarkNumber(char) and then convert this into an integer and then loop to that point printing every value.
Remember that a char is an integer type. When you cout and cin characters, the computer treats them specially to produce/read text that humans understand, but they are still just numbers.

Hope this helps.
I understand both these reply's but I still do not understand the question. If I was to read in characters and convert to integer
1
2
3
4
5
6
7
8
9
char MarkNumber (char);
int main(int argc, char** argv) {
    char a;
    int n;
    cin>>a;
    n=int(a);
    cout<<n;
    return 0;
}


This isn't consistent with his example input/output...

1
2
3
4
5
Input     Output
0         0
9         0123456789
19        01234567890123456789
25        01234567890123456789012345


Maybe vin in the first reply was closest...
Last edited on
I'm leaning toward turning this one in, but it reads in an integer and I'm not sure if that breaks the rules.


The Input values given by the instructor are integers and not ascii characters.

1
2
3
4
5
Input     Output
0         0
9         0123456789
19        01234567890123456789
25        01234567890123456789012345
Last edited on
weird right?..

I hate trick questions. So I will take an integer and put it into my function which calls for a character. Thanks all.
Sorry I meant you do this.

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

char MarkNumber (char);
int main(int argc, char** argv) {
    char n; //declare n as char integer
    cin>>n;
    MarkNumber(n);
    return 0;
}
char MarkNumber(char a)
{ 
    int i=0;
        while(a>=0)
        {         
         cout<<i;
         i++;
         a--;
                if(i==10){i=0;}
         
     }
}
Last edited on
Look at the output he gives you and start counting. Notice any pattern?
Topic archived. No new replies allowed.