Write a program with a function main () and selecting a menu of functions:
Generate a programming-random number generator data for lottery ticket / max 100 / with six-digit numbers and store them in an array
-Overwrite generated a new array and sort this array in ascending order and display output
-Counting and display output and numbers of all "happy" six digit lottery tickets /these numbers which sum of the first 3 digits is equal to the last three/
-Save in the array and display output sequence numbers of downloaded "lucky" lottery tickets
-Counting and display output and numbers of all "happy" six digit lottery tickets /these numbers which sum of the first 3 digits is equal to the last three/
-Save in the array and display output sequence numbers of downloaded "lucky" lottery tickets
I dont understend how to write this function, can someone help me?
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <iostream>
using namespace std;
int numbers;
int array[100];
void generator()
{
srand((unsigned)time(0));
for(int i = 0; i < 100; i++)
{
numbers = (rand() % 900000) + 100000;
array[i] = numbers;
cout << numbers << endl;
}
}
void sort()
{
int i = 100, a, b, c;
for (a = 0; a < i - 1; a++)
{
for(b = 1; b < i; b++)
{
if (array[b] < array[b - 1])
{
c = array[b];
array[b]= array[b - 1];
array[b - 1]=c;
}
}
}
for (a = 0; a < i; a++)
{
cout << a << ": " << array[a] << "\n";
}
}
}
int menu()
{
int choice;
cout<<"\n_______________MENU_______________";
cout<<"\n 1. Generate random numbers";
cout<<"\n 3. Sorted array";
do
{
cout<<"\n Choice: ";
cin>>choice;
}
while(choice<1||choice>3);
return(choice);
}
int main()
{
int i;
do
{
i=menu();
switch(i)
{
case 1: generator();break;
case 3: sort();break;
}
} 3
while(i!=4);
return 0;
}