## truthuntold

I am running into problem on getting this program done. Its suppose to quiz you on your 2 powers ie(2^2 = 4, 2^22 = 2m, 2^46 = 32t) I've programmed in python for a couple years but a lot of the tricks python lets us have C++ doesn't or I don't know how use them. As far as I've checked C++ doesn't have an append to array.

``````#include <CTime>
#include <CStdlib>
#include <conio.h>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main()
{
const int size = 20;
int penalty = 0;
int A[size];
int penaltyAmount = 5;
int timeStart;
int timeFinish;
int timeDiff;

// making unique random array
srand((unsigned)time(0));
for (int i = 0; i < size; i++)
{
A[i] = (rand()%50);
}
//debug array
/*
for (int i = 0; i < size; i++)
{
cout <<"i:" << i << " " << A[i] << " ";
}
*/
cout << "This program will quiz you on 2^ it will ask " << size << " questions. If you miss a question you will be penalized " << penaltyAmount << " seconds. Your responds";
cout << "will be in the form of 2^10 = 1k, 2^20 = 1m, 2^30 = 1b, 2^40 = 1t. Press enter when ready\n";
_getch();
//timing starts
timeStart = (int)time(0);
for(int i = 0; i < size; i++)
{

int Ones = A[i]%10;
int Tens = A[i]/10;

if(Ones == 0)
{
}
else if(Ones == 1)
{
}
else if(Ones == 2)
{
}
else if(Ones == 3)
{
}
else if(Ones == 4)
{
}
else if(Ones == 5)
{
}
else if(Ones == 6)
{
}
else if(Ones == 7)
{
}
else if(Ones == 8)
{
}
else if(Ones == 9)
{
}

if (Tens == 1)
{
}
else if (Tens == 2)
{
}
else if (Tens == 3)
{
}
else if (Tens == 4)
{
}

{
cout << "2^" << A[i] << "   ";
cout << "Wrong answer, try again" << endl;
}
}
timeFinish = time(0);
timeDiff = timeFinish - timeStart;
cout << timeDiff;

}``````

Thanks in advance for any help.

## WaltP 2,905

I am running into problem on getting this program done. Its suppose to quiz you on your 2 powers ie(2^2 = 4, 2^22 = 2m, 2^46 = 32t) I've programmed in python for a couple years but a lot of the tricks python lets us have C++ doesn't or I don't know how use them. As far as I've checked C++ doesn't have an append to array.

1) Don't use `getch()` , it's not standard. Use `getline()` 2) Append to array? Please be specific. Exactly what are you asking for? Depending, this could be yes or no.

## truthuntold

After I assign

``````A[0] = '1';
A[1] = '2';
A[2] = '8';``````

I want to append the Tens char on it. If its 2^10 add a 'k' to the end, 2^20 add a 'm' to the end and so on. I would just assign it to A[3] but it wouldn't work for 2^4(16_k) or it would be out of place on 2^14. For 2^14 it would have to be in A[2].

## WaltP 2,905

You need to keep track of the index yourself. Adter you load A[3] you need to remember that 4 is the next index:

``````A[idx] = num;
idx++;   // point at next A``````