-
Counting Page Numbers
Code:
#include <iostream.h>
#include "apvector.h"
int main()
{
apvector <int>num(6,0 );
apvector <int>page(6,0 );
apvector <int>temp(6,0 );
int cnt=0, len=0, x, p=0;
for (x=0; x<6; x++)
{
len = 0;
cout << "\nEnter page Number:";
cin >> num[x];
if (num[x] < 0)
break;
do {
num[x] = num[x]/10;
len++;
} while (num[x] > 0);
temp[x] = len;
cnt++;
}
}
The program is suppose to output:
123
136
139
1001
1021
1100
if the user enter numbers:
123
36
9
1001
1021
1100
The above code is incomplete: cant figure a way of adding em.
AP CLASS folder has been included
-
the simple answer is there is no call to cout except to ask user for input. Therefore it can never output anything but that statement.
However, a more significant problem is that the goal of the program is also unclear. Therefore I (and any other potential assistants) don't know how to help. Please be more descriptive if you can.
-
the object of the code is to output page numbers :D
lets say: if some user enter page numbers:
123
36
9
1001
1021
1100
The program is going to output numbers:
123
136
139
1001
1021
1100
For example: the first 2 numbers that user enters are 123 and 36
the program is going to make 123 to 100 and add 36 to 100 making the result 136, likewise if the user enters page number 9 and 1001 , the program is going to output 1001 since 1001 is a bigger number than 9 and comes after it (ie. the user entered it after he entered 9).
i hope this helps :rolleyes:
and yes the code is incomplete; thats y i didnt cout anything yet.