I'm new to C++ and C++ Builder; I was working before in python. I'm working on a project and I need some help.
I'm looking for a type that works the same as list does in Python. I have tried the vector but it doesn't work well for me. I need a variable where I can store random data in. I'm using rand()
to get the numbers but the numbers are not always different they will repeat itself. So I tried the BoxList
and it works for storing items in it. I Have done it in Python just so you can see what I'm trying to say to you all.
import random
pool= list()
for number in range(1,11):
pool.append(number)
random.shuffle(pool)
print(pool)
This would give me:
[6, 2, 10, 8, 9, 3, 7, 4, 5, 1] # or some other random shuffled numbers
The other idea is that I could check if the random number I'm looking for is in the BoxList
but I have no idea how to do that.
Edit: Im working in c++ builder and i have problems with getting the number to enter my ListBox.
Im doing a simple program that will help me study. i have like 100 questions and i would like it to ask me a question(the number of the question) and then i click one button if my answer was right and the other if my question was wrong.!
this is the code:
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include <vector>
#include <iostream>
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm3 *Form3;
int right = 0;
int wrong = 0 ;
int allQuestions = 0;
int currentQuestion = 0;
int toTheEnd = 0;
std::vector<int> asked;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button3Click(TObject *Sender)
{
allQuestions = Edit1->Text.ToInt();
right = 0;
wrong = 0;
Label1->Text = allQuestions;
toTheEnd = allQuestions;
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
right += 1;
toTheEnd -= 1;
Label1->Text = toTheEnd;
Label3->Text = right;
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button2Click(TObject *Sender)
{
wrong += 1;
toTheEnd -= 1;
Label1->Text = toTheEnd;
Label2->Text = wrong;
}
//---------------------------------------------------------------------------
I hope you guyz understand what im trying to say here if its not, plz tell me.