+ 1

Is there any problem concerning that code

#include <iostream> #include <string> #include <cmath> using namespace std; int main() { int agents,time,add; string name,people; char me; time = 20; cin>>name; cin>>agents; cin>>people; me=name[0]; add=0; long unsigned int i=0; for(i=0;i<people.size();i++) { if(isupper(people[i])) { if(people[i]<me) { add++; } } if (add==0) cout<<20; else if(add%agents==0) { cout<<add/agents*time; } else { cout<<add/agents*time+20; } } return 0; }

1st Aug 2021, 11:57 AM
Ahmed Jezi
3 ответов
+ 4
Ahmed Jezi , the code has to be reworked since there are several issues listed down: ▪︎input with cin >> people truncates input at the first occurring space. the input for the 4 peoples: Adam Caroline Rebecca Frank stores only "Adam" in the variable. it is better to use getline(...). ▪︎after having get this correctly, the input string with the 4 names has to be split to a vector (or an other suitable data structure), after this the vector has to be sorted, as demanded in the task description. ▪︎then you have to find the position of your name in the sorted list. ▪︎then calculate the time it will take until it is your turn (this description may not be complete. if you have any doubts, use additional outputs in code to see the variables content as a kind of debugging) happy coding and good success!
1st Aug 2021, 3:10 PM
Lothar
Lothar - avatar
+ 2
Ahmed Jezi , can you give us a bit more information what your concerns and doubts are? it looks like as if it is a code coach named "new driver's license? thanks!
1st Aug 2021, 12:11 PM
Lothar
Lothar - avatar
+ 1
Lothar the code outputs 20202020 Every time i try
1st Aug 2021, 1:54 PM
Ahmed Jezi