for(i=0;(a[i]=getchar())!='\n';i++);
I have no idea what's going on here. Is this meant to be fetching the input from the keyboard?
Firstly, you are not being charged by the letter. Here is a rule you should bear in mind forever; give your variables meaningful names. Do not call the input
a
.
Here is how to fetch the input in a way that's actually simple and easy to understand, instead of that character by character mess.
1 2
|
char input[100];
cin >> input; // do not enter an input that will exceed the size of the array
|
At this point, input is what the user typed, with a zero value on the end to mark the end of what they typed.
Do NOT call one of your arrays
z
. Do NOT call one of your arrays
m
. Do yourself a favour and give them names that make your code
easier to understand, rather than harder.
When you've got your two arrays (with zero value on the end to mark the end of your caracters), turn them into int values. This can be done like this:
int value = std::stoi(std:string(array));
This will require a compiler conformant to C++11. Since the year is 2016, I assume you've got a compiler that supports C++11 (from the year 2011).