Whats wrong with my code?

+1 vote
asked Oct 13 by Alhadi Fikri (130 points)
#include <lostream.h>
using namespace std;

int main();
{
    int nilai;
    cout<<"Masukkan Niai"<<end1;
    cin>>nilai;
    if (nilai<=100&&nilai>=82)
    {cout<<"A : Sangat Baik"<<end1;
        
    }else if(nilai<=81&&nilai>=71)
    {cout<<"B : Baik"<<end1;
        
    }else if(nilai<=70&&nilai>=60)
    {cout<<"C ; Cukup Baik"<<end1;
        
    }else if(nilai<=59&&nilai>=50)
    {cout<<"D : Kurang Baik"<<end1;
        
    }else if(nilai<=49&&nilai>=0)
    {cout<<"E : Buruk"<<end1;
        
    }else
    {cout<<“"Nilai Yg Di Masukkan Salah"<<end1;
        
    }
}

3 Answers

0 votes
answered Oct 14 by Peter Minarik (9,990 points)

Compile the code and look at the compilation errors (and warnings). That will tell you what the problem is.

You have to use the right names and syntax.

  1. It's not <lostream.h> but <iostream>.
  2. There supposed to be no semicolon (;) after the int main()
  3. It's not end1, but endl (or rather std::endl)
  4. '“"Nilai Yg Di Masukkan Salah"` has some extra characters before `"Nilai Yg Di Masukkan Salah"`, remove them.
+1 vote
answered Oct 14 by SSMalik99 (260 points)
1:-use <iostream> rather than <iostream.h>

2:-don't use semi-colon(;) after int main()

3:- put extra characters into else statement under quotation mark(" ")

4:-for c++ use endl; instead of end1;
0 votes
answered Oct 14 by Vithushan Vinayakamoorthy (140 points)
do not put ; after int main()

not end1 that is endl

not #include <lostream> that is #include <iostream>

 compare this line with your code    cout<<"“Nilai Yg Di Masukkan Salah"<<endl;

#include <iostream>
using namespace std;

int main()
{
    int nilai;
    cout<<"Masukkan Niai"<<endl;
    cin>>nilai;
    if (nilai<=100&&nilai>=82)
    {
        cout<<"A : Sangat Baik"<<endl;
        
    }
    else if(nilai<=81&&nilai>=71)
    {
        cout<<"B : Baik"<<endl;
        
    }
    else if(nilai<=70&&nilai>=60)
    {
        cout<<"C ; Cukup Baik"<<endl;
        
    }
    else if(nilai<=59&&nilai>=50)
    {
        cout<<"D : Kurang Baik"<<endl;
        
    }
    else if(nilai<=49&&nilai>=0)
    {
        cout<<"E : Buruk"<<endl;
        
    }
    else
    {
        cout<<"“Nilai Yg Di Masukkan Salah"<<endl;
        
    }
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...