c++ big help

Helo1

Well-known member
  • Sep 7, 2014
    2,782
    295
    83
    TrustWorld
    code eka liyala compier karapuwahama maa error eka anawa code ekan hari.:eek::eek:


    mama type karapu code eka


    #include <iostream>
    using namespace std;
    int main()
    {
    int val;
    int total=0;
    int counter=0;
    float avg;
    for(val=1;val !=0;){
    cout<<"enter your marks :";
    cin>>val;
    t
    avg=otal=total+val;
    counter++;
    }total/(counter-1);
    cout<<"\nthe total is :"<<total;
    cout<<"\nno of items enterd :"<<counter-1;
    cout<<"\nthe avareage is :"<<avg;
    return 0;
    }
    maccra code ekak mataka tiya ganna oniida???:eek::confused:



    ai maa error eka anna???

    Snapshot_1.jpg
     
    Last edited:
    • Like
    Reactions: Rasika212

    Pessimist

    Well-known member
  • Mar 6, 2018
    20,665
    1,562
    113
    🌎
    ඉතිං මී හරක් පැටියො කෝඩ් එක දැන්නැතුව මේක විතරක් දැම්මාම මේකෙ ඉන්න උන් උඹේ කෝඩ් එක දිවැසින් බලලද ප්‍රශ්නෙ මොකක්ද කියන්නෙ ? :rolleyes: :angry:
     

    Helo1

    Well-known member
  • Sep 7, 2014
    2,782
    295
    83
    TrustWorld
    ඉතිං මී හරක් පැටියො කෝඩ් එක දැන්නැතුව මේක විතරක් දැම්මාම මේකෙ ඉන්න උන් උඹේ කෝඩ් එක දිවැසින් බලලද ප්‍රශ්නෙ මොකක්ද කියන්නෙ ? :rolleyes: :angry:
    :P:P:P
     

    amila325

    Well-known member
  • Jul 11, 2006
    9,188
    33
    48
    code eka liyala compier karapuwahama maa error eka anawa code ekan hari.:eek::eek:


    mama type karapu code eka


    #include <iostream>
    using namespace std;
    int main()
    {
    int val;
    int total=0;
    int counter=0;
    float avg;
    for(val=1;val !=0;){
    cout<<"enter your marks :";
    cin>>val;
    t
    avg=otal=total+val;
    counter++;
    }total/(counter-1);
    cout<<"\nthe total is :"<<total;
    cout<<"\nno of items enterd :"<<counter-1;
    cout<<"\nthe avareage is :"<<avg;
    return 0;
    }
    maccra code ekak mataka tiya ganna oniida???:eek::confused:



    ai maa error eka anna???

    View attachment 74001
    Not a solution but tru using a do while loop here
    do{
    count <<
    cin >>

    }while(val != 0)

    And other thing is when you divide two integers result is also a integer
    Read this https://stackoverflow.com/questions/12447325/dividing-two-integers-to-produce-a-float-result
     
    • Like
    Reactions: Helo1

    imhotep

    Well-known member
  • Mar 29, 2017
    14,823
    8
    35,325
    113
    Syntax errors and undefined variables...:eek:
    Change to below...

    #include <iostream>
    using namespace std;
    int main()
    {
    int val;
    int total=0;
    int counter=0;
    float avg;
    for(val=1;val!=0; 1){
    cout<<"enter your marks :";
    cin>>val;
    avg=total+val;
    counter++;
    };total/(counter-1);
    cout<<"\nthe total is :"<<total;
    cout<<"\nno of items enterd :"<<counter-1;
    cout<<"\nthe avareage is :"<<avg;
    return 0;
    }