0

Where is error in my code? Plz locate?

#include <iostream> using namespace std; class result { private: int rno; int marks[3]; //for storing marks char name[50]; //for storing names public: void input() { cout<<"Enter rno:"; cin>>rno; cout<<"Enter name"; gets(name); //for loop for storing values in marks for(int i=0; i<3; i++){ cout<<"Enter marks of 3 subjects:\n"; cin>>marks[i]; } void show() { cout<<"Roll No.:"<<rno<<endl; cout<<"Name:"<<name<<endl; for(int i<0; i<3; i++) cout<<"Marks["<<i<<"]"<<marks[i]<<endl; } int total() { int t=0; for(int i=0; i<3; i++) t=t + marks[i]; return t; } float avg(){ for(int i=0; i<3; i++) t=t+marks[i]; return t/3.0; } }; int main(){ result r; r.input(); r.show(); cout<<"Total is"<<r.total(); cout<<"Average is"<<r.avg(); return 0; }

4th Jun 2021, 4:09 AM
Numan Iftikhar
Numan Iftikhar - avatar
2 Answers
0
Use fgets() function instead of gets() and also include string headerfile check all parentheses properly
4th Jun 2021, 4:18 AM
đŸ’«AsđŸ’«
đŸ’«AsđŸ’« - avatar
0
As A.S. suggested use fgets() instead of gets(), In show method implementation ,init condition is wrong should be i=0, In avg method declare t ,bcz t declared in total hasn't scope outside of total,
4th Jun 2021, 5:14 AM
saurabh
saurabh - avatar