Hey guys, I am confused on how to do this code. The specifications are in the attachment. It is a word file. This is the code that I have so far. It does not work to what is asked for and I don't know where to go from here.

#include <iostream>
using namespace std;

const int MAXDIGITS = 100;

void inputVLI(int vli[], int& size);
void outputVLI(int vli[], int& size);
void addVLI(int vli1[], int vli2[], int vli3[], int size1, int size2, int& size3);
int compVLI(int vli1[], int vli2[], int size1, int size2);

int main()
{
	int size1 = 0, size2 = 0, size3 = 0;
	int vli1[MAXDIGITS], vli2[MAXDIGITS], vli3[MAXDIGITS];
	inputVLI(vli1, size1);
	inputVLI(vli2, size2);
	outputVLI(vli1, size1);
	outputVLI(vli2, size2);
	addVLI(vli1, vli2, vli3, size1, size2, size3);
	if(compVLI(vli1, vli2, size1, size2) == 1)
		cout << "The first number is larger than the second one." << endl;
	else if(compVLI(vli1, vli2, size1, size2) == -1)
		cout << "The second number is larger than the first one." << endl;
	else
		cout << "They are both equal." << endl;

	return 0;
}

void inputVLI(int vli[], int& size)
{
	cout << "Enter a lot of numbers but less than 100 times." << endl;
	for(char digit = '0'; '0' <= digit <= '9'; size++)
	{
		cin >> digit;
		vli[size] = int(digit - '0'); break;
	}
}

void outputVLI(int vli[], int& size)
{
	cout << "The first set = " << endl;
	for(int i = 0; i >= size; i++)
	cout << vli[i] << " ";

}

void addVLI(int vli1[], int vli2[], int vli3[], int size1, int size2, int& size3)
{
	int sizefinal;
	cout << "When you add them together, you get: " << endl;
	if(size1 >= size2)
		sizefinal = size1;
	else
		sizefinal = size2;
	for(int size3 = 0; size3 <= sizefinal; size3++)
	{
		vli3[size3] = vli1[size3] + vli2[size3];
		cout << vli3[size3] << " ";
	}

}

int compVLI(int vli1[], int vli2[], int size1, int size2)
{

	int sizefinal;
	if(size1 >= size2)
		sizefinal = size1;
	else
		sizefinal = size2;
	for(int i = 0; i <= sizefinal; i++)
	{
		if(vli1[i] == vli2[i])
			return 0;
		else if (vli1[i] > vli2[i])
			return -1;
		else
			return 1;
	}
	return 0;
}

I'm not going to take the time to download and read your Word-format document, since you didn't take the time to copy&paste the most minimal portion of it into your post.

That said, your logic is flawed in your inputVLI routine: you're inputting a "digit" and storing its integer value into the array (and breaking out of your loop on no basis whatsoever), before you check whether the input is OK. Talk through what needs to happen each time the user types a key, and then code that. And your test-expression ('0' <= digit <= '9') is invalid, you have to break it into two relational tests. How would you read that out loud? "zero is less-than-or-equal-to digit and digit is less-than-or-equal-to nine". Implement that.

Now try it yourself before looking carefully at the following!

No peeking!

OK, fine, peek. :) Try this:

void inputVLI(int vli[], int& size)
{
    cout << "Enter a lot of numbers but less than 100 times." << endl;
    size = 0;
    char digit;
    while (size < 100) {
        cin >> digit;
        if (digit < '0' || digit > '9')
            break;
        vli[size] = int(digit - '0');
        size++;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.