Number that corresponds to ASCII table?

Hello all,
Beginner C++ programmer here...
I need to write a program that asks a user to input a positive number, and once they do, it asks for options for the user to select. I'm working on this slowly, so I'm just concerned with the first part. When they select option a or A, it calls for a user defined function that displays whether the ASCII argument corresponds to a digit, uppercase letter or lowercase letter or none of the above. My question is, do I use for loops and counters within my switch for the ranges of the digits, lowercase and uppercase letters? Or do I do that in the user defined function? Am I not calling the function correctly? I'm confused on this part. Thanks for the time...
Here's a sample of what I have so far....any advice is greatly appreciated, if I'm going on the right path. I do have one error,as the program stands when I just try to run it to test it to see what it does.


Here's the error:
error C2440: 'initializing' : cannot convert from 'void' to 'int'
1> Expressions of type void cannot be converted to other types

And a portion of my code:


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
43
44
void ascii (int number);
 

int main ()	
{		
	
	int value;
	char option;
	cout <<"Enter a positive integer number: " <<endl;
	cin >>value;
	cout <<endl;

	cout <<"A[scii]" "\t\tR[affle]" "\t\tE[xit]" <<endl;
	cout <<"Please select an option: " <<endl;
	cin >>option;

	switch (option)
	{
		case 'a':
		case 'A':

		int i,j,k;
		
		 for (i=48; i<=57; i++) //range for the digits in ASCII table
			cout <<"Enter a positive integer number: " <<endl;
			cin >>value;
			cout <<endl;
			cout <<"A[scii]" "\t\tR[affle]" "\t\tE[xit]" <<endl;
			cout <<"Please select an option: " <<endl;
			cin >>option;
		 
		
		 int numberascii = ascii(value);

		break;

	}
}


void ascii (int value)
{
	cout <<"The number you have entered corresponds to a digit in the ASCII table." <<endl;
}





Last edited on
Hiya! It appears that it's your first post, so welcome to cplusplus!
First off, when posting code, please use code tags for better readability. To do so, just put these blocks [ code ] and [ /code ] (without the spaces) around the part of your post that's code.

Anyway, the error you described above appears to be from here:

1
2
3
4
5
6
void ascii (int number); //this is your declaration of your ascii function, note it has a void return type

//.. later in your code
int numberascii = ascii(value);

//there you're asking your ascii function to return a value that it's not. 


Change void ascii() to int ascii().

Also note that it won't assign a value to 'numberascii' yet, as you haven't returned any value in the ascii function.
Last edited on
Topic archived. No new replies allowed.