#include <iostream>
using namespace std;


struct student

{

 char name [50];
 char   S_code [5];
 int fees;
};


 void display(struct student);
 double input(struct student&);

  int main()

{

   double total;
   student stu;
   total=input(stu);
   display(stu);
   input(stu);





   return 0;
}


  double input (struct student&stu )
 {

 double total=0;
  char again ='y';
  cin.getline (stu.name,50);

 while (again =='y');


 {
   cin>>stu.S_code>>stu.fees;

   total=total+stu.fees;

   cin>>again;
 }


 return total;
 }

void display(struct student stu,double totalfees)
{
cout<<"total fee for"<<stu.name<<"is"<<totalfees<<endl;

}

Edited 4 Years Ago by Dani: Formatting code

correct the parameters of the display function to match the one in main and it's function prototype

she means that the parameters on line 15 and line 58 do not match. They have to be the same. Also, its best to always pass structures around by reference, never by value, because the program has to duplicate everything in the structure when it is passed by value. You are doing that for the input function, but not for the display function. Passing by value takes CPU time and can slow down your program. Of course it won't be noticeable in simple programs like you are writing, but it will have a performance hit on large programs. So you should get into the habbit of passing structures/classes around by reference now so that you don't have to unlearn bad habbits later on.

Edited 4 Years Ago by Ancient Dragon

15. void display(student stu, double totalfees);
25. display(stu, total);

Edited 4 Years Ago by misokolsky: Incorrect answer.

thanks guys i have fix the bugs but it is not displaying anything....

include <iostream>

using namespace std;

struct student

{

char name [50];
char S_code [5];
int fees;
};

void display(student stu, double totalfees);
double input(struct student&);

int main()
{
double total;
student stu;
total=input(stu);
display(stu, total);
input(stu);
system("Pause");

return 0;
}

double input (struct student &stu )
{

double total=0;
char again ='y';
cin.getline (stu.name,50);

while (again =='y');

{
cin>>stu.S_code>>stu.fees;

total=total+stu.fees;

cin>>again;
}

return total;
}

void display(struct student stu,double totalfees)

{
cout<<"total fee for"<<stu.name<<"is"<<totalfees<<endl;
}

include <iostream>

using namespace std;

struct student
{
char name [50];
char S_code [5];
int fees;
};

void display(student stu, double totalfees);
double input(student&);

int main()
{
double total;
student stu;
total=input(stu);
display(stu, total);
return 0;
}

double input (student & stu)
{
double total=0;
char again ='y';
while (again == 'y')
{
cout << "Input name: ";
cin >> stu.name;
cout << "Input code and fees: ";
cin>>stu.S_code>>stu.fees;
total=total+stu.fees;
cout << "Again? Y/n: ";
cin >> again;
}
return total;
}

void display(student stu,double totalfees)
{
cout<<"total fee for "<<stu.name<<" is "<<totalfees<<endl;
}

Output:

./stu
Input name: Olivia
Input code and fees: 77
7
Again? Y/n: y
Input name: Bob
Input code and fees: 45
7
Again? Y/n: y
Input name: Conway
Input code and fees: 99
7
Again? Y/n: n
total fee for Conway is 21

Enjoy.

Comments
giving too much code away

thanks alot..................u r very heplfull....................

This article has been dead for over six months. Start a new discussion instead.