Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ How can I get this program to repeat when the selection is greater than 2, that is its a wrong selection on the menu....IT

C++

How can I get this program to repeat when the selection is greater than 2, that is its a wrong selection on the menu....IT IS MY ELSE STATEMENT YET I NEED IT TO CONTINUE and PROMPT WRONG OPTION....

include

using namespace std;

void displayClassInfoTameemB(void);

int getLargestIntegerWithLargestTUEDC(int *getinteger, int getSize, int *counterArray);

int main() {

displayClassInfoTameemB();

int selection;

cout << "********************************";

cout << "******************************** ";

cout << " *\t\t\t MENU - HW #1 \t\t\t\t* ";

cout << " *\t 1. Calling getLargestIntegarWithLargestTUEDC() \t* ";

cout << "*\t 2. Quit \t\t\t\t\t\t* ";

cout << "********************************";

cout << "******************************** ";

cout << " Enter an integar for option + ENTER: ";

cin >> selection;

if (selection == 1) {

int *getinteger = nullptr;

int getSize;

int count;

cout << "How many integers :";

cin >> getSize;

getinteger = new int[getSize];

// DYNAMICALLY CREATE AN ARRAY WITH THE SIZE INPUT BY THE USER

int *counterArray = new int[getSize]();

// DYNAMICALLY CREATE ANOTHER ARRAY OF INTEGERS WHICH WILL STORE THE TOTAL NUMBER OF EVEN NUMBERS

// ALL VALUES ARE SET TO ZERO AS CONSIDERING INITIALLY THAT THERE IS NO EVEN VALUE IN THE ELEMENTS

// NOTE THE PARANTHESIS, IT IS USED TO INITIALISE ALL ELEMENTS TO ZERO

for (count = 0; count < getSize; count++) {

cout << "Enter the integar # " << (count + 1) << ": ";

cin >> getinteger[count];}

cout << "The original array is as follows:" << endl;

for (count = 0; count < getSize; count++) {

cout << getinteger[count] << endl;}

cout << "The largest unique EVEN digit count is :";

cout << getLargestIntegerWithLargestTUEDC(getinteger, getSize, counterArray);

cout << endl;

delete[] getinteger;

getinteger = nullptr;}

else if (selection == 2) {

cout << "End Program!";

}

else {

cout << "Wrong Option!";

selection == 1;

}

system("pause");

return 0;

}

void displayClassInfoTameemB() {

cout << " CIS 25 - C++ Programming ";

cout << " Laney College ";

cout << " Tameem Bahram ";

cout << " Assignment Information - - ";

cout << " Assignment Number : \t Homework 1, ";

cout << " \t \t \t \t Coding Assigment - - Exercise #1 ";

cout << " Written by : \t \t Tameem Bahram ";

cout << " Submitted Date : \t \t 6/2/2018 ";}

int getLargestIntegerWithLargestTUEDC(int *getinteger, int getSize, int *counterArray) {

int TUEDC;

int remainder, digit, number;

// REMAINDER IS FOR CHECKING THE LAST DIGIT

for (int count = 0; count < getSize; count++) {

if (getinteger[count] == 0)

counterArray[count]++;

else {

number = getinteger[count];

while (number != 0) {

digit = number % 10;

remainder = digit % 2;

number = number / 10;

// TO MOVE TO NEXT PLACE IN THE NUMBER

if (remainder == 0)

counterArray[count]++;

}

}

}

TUEDC = 0;

// LET FIRST ELEMENT BE THE TUEDC OF THE ARRAY

for (int count = 0; count < getSize; count++) {

//WILL CHECK ALL THE NUMBERS WHICH HAVE HIGHEST NUMBER OF EVEN DIGITS

if (counterArray[TUEDC] < counterArray[count])

TUEDC = count;

}

return getinteger[TUEDC];

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

Can anyone help with me with the attached case? Thanks!

Answered: 1 week ago

Question

What will you do or say to Anthony about this issue?

Answered: 1 week ago