In case I need to generate 5 random numbers, and insert them into a dynamic list, I have been trying, but the maximum I can is to generate and display them
follow code:
#include <iostream>
#include <cstdlib>//Biblioteca responsavel por numeros aleatorios
#include <ctime>//Biblioteca responsavel por numeros aleatorios
#include <list>//Biblioteca responsavel por criar listas
#define PCT 5
using namespace std;
typedef struct Album{
int figura;
Album *prox;
/* list<int> album;
int tam;
tam=681;
for(int i=tam; i>0; i--){
album.push_front(i);
}
cout<<"Album da copa 2018 - total "<<album.size()<<" figurinhas"<<endl<<endl;
tam=album.size();
for(int i=0; i < tam; i++){
cout<<album.front()<<endl;
album.pop_front();
}*/
};
Album *inicio = NULL;
Album *fim = NULL;
Album *aux;
Album *anterior;
void Pacote(){
system("cls");
srand((unsigned)time(0)); //para gerar numeros aleatorios reais.
for (int i=0; i<PCT; i++){
int maior = 681;
int menor = 1;
int Figurinha = rand()%(maior-menor+1) + menor;
cout << Figurinha << endl; }
//Valida();
Album *novo = new Album();
cin>>novo->figura;
if (inicio==NULL){
inicio = novo;
novo->prox=NULL;
}
else{
anterior=NULL;
aux=inicio;
while (aux != NULL && novo -> figura > aux->figura){
anterior = aux;
aux = aux->prox;
}
if (anterior==NULL){
novo->prox=inicio;
inicio=novo;
}
else if (aux==NULL){
fim->prox=novo;
fim = novo;
fim->prox=NULL;
}
else{
anterior->prox=novo;
novo->prox=aux;
}
}
}
/*void Valida(int Figurinha, list<int> album){
if (Figurinha ){
}*/
void Menu(){
int x=0;
system("color F0");
do{
cout<<"==========ALBUM DA COPA========="<<endl;
cout<<"1 - Inserir novas figurinhas"<<endl;
cout<<"2 - Exibir album"<<endl;
cout<<endl<<endl<<"Selecione uma das opcoes acima :"<<endl;
cin>>x;
switch (x){
case 1:
Pacote();
break;
case 2:
Album();
break;
}
}while (x!=5);
}
int main(int argc, char** argv) {
Menu();
return 0;
}