Answer to Question #349900 in C++ for Magisk

Question #349900

Inst.

  1. Implement the findRing() function w/ the ff. details
  2. Return type int
  3. Name findRing
  4. Parameters
  5. int* - rings array
  6. int - array size of rings
  7. int - ring she wants
  8. Return value - the index of the ring in the array of rings.

Given code

#include <iostream>

using namespace std;

// TODO: Declare findRing()


int main(void) {

  int rings[10];


  for(int i = 0; i < 10; i++) {

    cout << "Enter option #" << i + 1 << ": ";

    cin >> rings[i];

  }


  int wantedRing;

  cout << "Enter the ring she wants: ";

  cin >> wantedRing;


  cout << endl << "Ring " << wantedRing << " is found at option " << findRing(rings, 10, wantedRing) + 1 << "!";


  return 0;

}


// TODO: Define findRing()


Ex

Enter option #1: 5

Enter option #2: 3

Enter option #3: 10

Enter option #4: 9

Enter option #5: 13

Enter option #6: 11

Enter option #7: 20

Enter option #8: 25

Enter ring she wants: 25


Ring·25 found·at·option·8


1
Expert's answer
2022-06-13T08:27:49-0400
#include <iostream>

using namespace std;

// TODO: Declare findRing()

int findRing(int rings_arr[], int arr_size, int wantedRing);

int main(void) {

    int rings[10];


    for (int i = 0; i < 10; i++) {

        cout << "Enter option #" << i + 1 << ": ";

        cin >> rings[i];

    }


    int wantedRing;

    cout << "Enter the ring she wants: ";

    cin >> wantedRing;


    cout << endl << "Ring " << wantedRing << " is found at option " << findRing(rings, 10, wantedRing) + 1 << "!";


    return 0;

}

int findRing(int rings_arr[], int arr_size, int wantedRing) {
    // Let's loop through the array
    for (int i = 0; i < 10; i++) {
        // And check each element
        if (rings_arr[i] == wantedRing) {
            // If element value is equal to wantedRing, then return element index
            return i;
        }
    }
    // If the value of no element is equal to wantedRing, then return -1 (not found)
    return -1;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS