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