0
how to start a function in this app?
I mean to say that where l should put the curly bracket . when I am executing the program,for instance, a class's program it is giving error.
3 Answers
+ 1
Include your code please, so we can help!
+ 1
You have a lot of syntax errors. No semicolons after method names. the cout and cin operators are wrong. You cannot have two return statements in a method.
I have corrected your code, check this out!
#include<iostream>
using namespace std;
class student
{
int rollno;
string name;
float s1,s2,s3,average,total;
public:
void input() {
cout<<"enter name:"<<endl;
cin>>name;
cout<<"enter rollno:"<<endl;
cin>>rollno;
cout<<"enter marks ofsub1,sub2,sub3"<<endl;
cin>>s1>>s2>>s3;
}
void calculate() {
total=s1+s2+s3;
average=total/3;
}
void output() {
cout<<"name is "<<name<<endl;
cout<<"roll no is "<<rollno<<endl;
cout<<"marks in sub1,sub2 and sub3 "<<s1<<s2<<s3<<endl;
cout<<"total is "<<total<<endl;
cout<<"average is "<<average<<endl;
}
};
int main()
{
student st;
st.input();
st.calculate();
st.output();
}
0
#include<iostream>
using namespace std;
class student
{int rollno;
char name[25];
float s1,s2,s3,avg,total;
public:
void input();
{cout"enter name:";
gets(name);
cout<<"enter rollno:";
cin>>rollno;
cout>>"enter marks ofsub1,sub2,sub3";
cin>>"s1>>s2>>s3";
}
void calculate();
{total=s1+s2+s3;
return total;
average=total/3;
return avg;
}
void output();
{cout<<"name is"<<name;
cout<<"roll no is"<<rollno;
cout<<"marks in sub1,sub2 and sub3"<<s1<<s2<<s3;
cout<<"total is"<<total;
cout<<"average is"<<avg;
}
};
int main()
{
student st;
st.input();
st.calculate();
st.output();
}