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
//my code
#include <iostream>
#include <string>
using namespace std;
//complete the function
void winners(string customers[13],int x,int m) {
for(x=0;x<13;x++){
if((x+1)%m==0){
cout<<customers[x]<<endl;
}
}
}
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;
}
2261

被折叠的 条评论
为什么被折叠?



