0

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;
}
2
Contributors
1
Reply
5
Views
4 Years
Discussion Span
Last Post by Lucaci Andrew
0

Didn't these guys help you out? Since you have asked for their help also?...
Click Here

Here's something that can help you: this function will return true if the number is a happynumber, or false otherwise:

bool happyNr(int a){
    if (a<100000 || a>999999) return false;
    int half1=0, half2=0;
    for (int i=0;i<6;i++){
        if (i<3) {half1+=a%10; a=a/10;}
        else {half2+=a%10; a=a/10;}
    }
    return half1==half2;
}

Now, try to figure out the other problems. Good luck.

Edited by Lucaci Andrew

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.