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;
char answer[10];
// 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)
{
answer[0] = '1';
}
else if(Ones == 1)
{
answer[0] = '2';
}
else if(Ones == 2)
{
answer[0] = '4';
}
else if(Ones == 3)
{
answer[0] = '8';
}
else if(Ones == 4)
{
answer[0] = '1';
answer[1] = '6';
}
else if(Ones == 5)
{
answer[0] = '3';
answer[1] = '2';
}
else if(Ones == 6)
{
answer[0] = '6';
answer[1] = '4';
}
else if(Ones == 7)
{
answer[0] = '1';
answer[1] = '2';
answer[2] = '8';
}
else if(Ones == 8)
{
answer[0] = '2';
answer[1] = '5';
answer[2] = '6';
}
else if(Ones == 9)
{
answer[0] = '5';
answer[1] = '1';
answer[2] = '2';
}
if (Tens == 1)
{
answer[strlen(answer)] = 'k';
}
else if (Tens == 2)
{
answer[strlen(answer)] = 'm';
}
else if (Tens == 3)
{
answer[strlen(answer)] = 'b';
}
else if (Tens == 4)
{
answer[strlen(answer)] = 't';
}
char userAnswer[10];
while(strcmp (answer, userAnswer) !=0)
{
cout << "2^" << A[i] << " ";
cin >> userAnswer;
cout << answer;
if(strcmp (answer, userAnswer) !=0)
cout << "Wrong answer, try again" << endl;
}
}
timeFinish = time(0);
timeDiff = timeFinish - timeStart;
cout << timeDiff;
}
Thanks in advance for any help.