2. Find the ring! by CodeChum Admin Thanks to you, my crush was impressed with my awesome display() function!! I'm now planning to propose to her, but I need to find the best ring available in the market as she is truly special to me. Can you help me find the ring that she wants? Instructions: In the code editor, you are provided with the main() function that asks the user for 10 elements that represents the options for the ring as well as a single integer value that represents the ring that she wants. Then, a call to the findRing() function is made and the array of rings and the ring she wants are passed into it. Your task is to implement the findRing() function. This has the following details: Return type - int Name - findRing Parameters int* - for the array of rings int - size of the array of rings int - the ring that she wants Return value - the index of the ring in the array of rings. It is guaranteed that there is only one such ring that matches the ring that she wants. Input 1. Ten integer values representing the rings 2. Integer value representing the ring she wants Output 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·option·#9:·4 Enter·option·#10:·3 Enter·the·ring·she·wants:·25 Ring·25·is·found·at·option·8! EDIT THIS CODE: #include using namespace std; // TODO: Declare the findRing() here 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 the findRing() here
2. Find the ring!
by CodeChum Admin
Thanks to you, my crush was impressed with my awesome display() function!!
I'm now planning to propose to her, but I need to find the best ring available in the market as she is truly special to me.
Can you help me find the ring that she wants?
Instructions:
- In the code editor, you are provided with the main() function that asks the user for 10 elements that represents the options for the ring as well as a single integer value that represents the ring that she wants. Then, a call to the findRing() function is made and the array of rings and the ring she wants are passed into it.
-
Your task is to implement the findRing() function. This has the following details:
- Return type - int
- Name - findRing
-
Parameters
- int* - for the array of rings
- int - size of the array of rings
- int - the ring that she wants
- Return value - the index of the ring in the array of rings. It is guaranteed that there is only one such ring that matches the ring that she wants.
Input
1. Ten integer values representing the rings
2. Integer value representing the ring she wants
Output
#include <iostream>
using namespace std;
// TODO: Declare the findRing() here
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 the findRing() here
Step by step
Solved in 3 steps with 1 images