fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. // your code goes here
  7.  
  8. int scores[51], int newscore, int maxlen;
  9.  
  10. scores = {66, 54, 23, 12};
  11. newscore = 45;
  12. maxlen=51;
  13.  
  14. printf("%d\n", getRank(scores, newscore, maxlen));
  15. return 0;
  16. }
  17.  
  18. double getRank(int scores[], int newscore, int maxlen) {
  19.  
  20. int scoresLength = sizeof(scores)/sizeof(scores[0]);
  21.  
  22. for(i=0;i<scoresLength;i++){
  23. if( newscore > scores[i]){
  24. return i+1;
  25. }else{
  26. if(newscore = scores[i]){
  27. if(i < maxlen-1)
  28. return i+1;
  29. }
  30. }
  31. }
  32. return -1;
  33.  
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:8:18: error: expected unqualified-id before ‘int’
  int scores[51], int newscore, int maxlen;
                  ^~~
prog.cpp:10:26: error: assigning to an array from an initializer list
  scores = {66, 54, 23, 12};
                          ^
prog.cpp:11:2: error: ‘newscore’ was not declared in this scope
  newscore = 45;
  ^~~~~~~~
prog.cpp:12:2: error: ‘maxlen’ was not declared in this scope
  maxlen=51;
  ^~~~~~
prog.cpp:14:49: error: ‘getRank’ was not declared in this scope
  printf("%d\n", getRank(scores, newscore, maxlen));
                                                 ^
prog.cpp: In function ‘double getRank(int*, int, int)’:
prog.cpp:20:36: warning: ‘sizeof’ on array function parameter ‘scores’ will return size of ‘int*’ [-Wsizeof-array-argument]
    int scoresLength = sizeof(scores)/sizeof(scores[0]);
                                    ^
prog.cpp:18:27: note: declared here
 double getRank(int scores[], int newscore, int maxlen) {
                           ^
prog.cpp:22:8: error: ‘i’ was not declared in this scope
    for(i=0;i<scoresLength;i++){
        ^
stdout
Standard output is empty