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
18 Réponses
+ 3
Which strings? Which logic?
Can you please link your code or elaborate what you are referring to?
+ 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;
}
+ 2
Here is up 👆
+ 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)
+ 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;
}
+ 2
That's better, but the names are not the same in the output.
+ 2
I got the your thought, Lisa. Thanks!
+ 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;
}
+ 2
The string <if (x==n){ > wasn't lead to success
+ 2
What's the <x> does mean?
+ 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.
+ 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;
}
+ 2
In my own solution, I tested if if customers[i] is a n-th customer by checking if (i+1) % n == 0
+ 1
C++\\practice\\43.2
+ 1
Can you copy your code into a playground script and link it here?
The task seemed to work for me...
+ 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.
+ 1
Here is right code 👆, unfortunately didn't it myself 🙁 I fixed it a litte 🙂