+ 1

Who's The Lucky Winner?

Help, I can't finish this practice it goes like: A local supermarket is running a promotion: each Nth customer will receive one item for free. Customers names are sequentially given as array of strings (see template). Write a function that receives the array of customers, its size, and the N number as arguments, and prints the names of the lucky customers each in a new line. Sample Input 3 Sample output Rayan Bruce Richard Mary

28th Jun 2021, 10:26 PM
Mihályi Milán
Mihályi Milán - avatar
3 Respuestas
+ 3
void lucky(string list[], int len, int N) { for (int i=N-1; i<len; i+=N) { cout << list[i] << endl; } }
29th Jun 2021, 12:01 AM
visph
visph - avatar
+ 1
If(i%n==0) cout << list[i] << endl;
30th Jun 2021, 6:26 AM
Filip Dobeš
0
#include <iostream> #include <string> using namespace std; //complete the function void winners(string array[], int size, int lucky) { int whosNext = lucky; for(int i=0; i < size; i++){ if(i == whosNext){ cout << array[i-1] << endl; whosNext += lucky; } } } int main() { string customers[] = {"Alice", "Bob", "Rayan", "Emma", "Ann", "Bruce", "Synthia", "Daniel", "Richard", "Sam", "Nick", "Mary", "Paul"}; //getting the lucky number as input int n; cin >> n; //call function winners(customers, 13, n); return 0; }
11th Jul 2022, 8:33 PM
Andrew Cieslik
Andrew Cieslik - avatar