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.

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.

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].

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
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.