0

What's the mistake?

I don't see the words in to strings, secondly where is logic? https://sololearn.com/coach/444/?ref=app

13th Nov 2021, 9:08 PM
Vladimir Kushner
Vladimir Kushner - avatar
18 ответов
+ 3
Which strings? Which logic? Can you please link your code or elaborate what you are referring to?
13th Nov 2021, 9:09 PM
Lisa
Lisa - avatar
+ 2
#include <iostream> #include <string> using namespace std; //завершите функцию void winners(string customers[], int size, int n){ for (int x=0; x<n; x++){ cout<<customers<<endl; } } int main() { string customers[] = {"Alice", "Bob", "Rayan", "Emma", "Ann", "Bruce", "Synthia", "Daniel", "Richard", "Sam", "Nick", "Mary", "Paul"}; //получаем номер счастливчика int n; cin >> n; //вызываем функцию winners(customers, 13, n); return 0; }
13th Nov 2021, 9:33 PM
Vladimir Kushner
Vladimir Kushner - avatar
+ 2
Here is up 👆
13th Nov 2021, 9:33 PM
Vladimir Kushner
Vladimir Kushner - avatar
+ 2
In your winners function, inside the loop, an if statement is needed: only output the n-th customer (only customer[x], not the whole array)
13th Nov 2021, 9:35 PM
Lisa
Lisa - avatar
+ 2
#include <iostream> #include <string> using namespace std; //завершите функцию void winners(string customers[], int size, int n){ for (int x=0; x<n; x++){ cout<<customers[x]<<endl; } } int main() { string customers[] = {"Alice", "Bob", "Rayan", "Emma", "Ann", "Bruce", "Synthia", "Daniel", "Richard", "Sam", "Nick", "Mary", "Paul"}; //получаем номер счастливчика int n; cin >> n; //вызываем функцию winners(customers, 13, n); return 0; }
13th Nov 2021, 9:50 PM
Vladimir Kushner
Vladimir Kushner - avatar
+ 2
That's better, but the names are not the same in the output.
13th Nov 2021, 9:54 PM
Vladimir Kushner
Vladimir Kushner - avatar
+ 2
I got the your thought, Lisa. Thanks!
13th Nov 2021, 9:56 PM
Vladimir Kushner
Vladimir Kushner - avatar
+ 2
#include <iostream> #include <string> using namespace std; //завершите функцию void winners(string customers[], int size, int n){ for (int x=0; x<size; x++){ if (x==n){ cout<<customers[x]<<endl; } } } int main() { string customers[] = {"Alice", "Bob", "Rayan", "Emma", "Ann", "Bruce", "Synthia", "Daniel", "Richard", "Sam", "Nick", "Mary", "Paul"}; //получаем номер счастливчика int n; cin >> n; //вызываем функцию winners(customers, 13, n); return 0; }
14th Nov 2021, 9:36 AM
Riddler Clash
Riddler Clash - avatar
+ 2
The string <if (x==n){ > wasn't lead to success
14th Nov 2021, 9:30 PM
Vladimir Kushner
Vladimir Kushner - avatar
+ 2
What's the <x> does mean?
14th Nov 2021, 9:31 PM
Vladimir Kushner
Vladimir Kushner - avatar
+ 2
The code outputs only the first n-th customer – the task requires to out put each n-th customer. Please pay attention to the task instructions.
14th Nov 2021, 9:51 PM
Lisa
Lisa - avatar
+ 2
#include <iostream> #include <string> using namespace std; //complete the function void winners(string costumers[],int size,int n) { int k=1; for (int i=0 ; i<=size ;i++ ) { if ( (n*k-1)<=13){ cout<<costumers[(n*k)-1]<<endl; k++; } } } 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; }
17th Nov 2021, 9:36 PM
Vladimir Kushner
Vladimir Kushner - avatar
+ 2
In my own solution, I tested if if customers[i] is a n-th customer by checking if (i+1) % n == 0
17th Nov 2021, 9:45 PM
Lisa
Lisa - avatar
+ 1
C++\\practice\\43.2
13th Nov 2021, 9:15 PM
Vladimir Kushner
Vladimir Kushner - avatar
+ 1
Can you copy your code into a playground script and link it here? The task seemed to work for me...
13th Nov 2021, 9:31 PM
Lisa
Lisa - avatar
+ 1
Currently your function output every customer. However, we only need to print the n-th customer. You can accomplish it with an if-statement.
13th Nov 2021, 9:55 PM
Lisa
Lisa - avatar
+ 1
Here is right code 👆, unfortunately didn't it myself 🙁 I fixed it a litte 🙂
17th Nov 2021, 9:40 PM
Vladimir Kushner
Vladimir Kushner - avatar