I want to create a struct array and get the max number of books written by particular author...The problem is that i can't get the number.
I am not finished up yet with the code,but i don't know why i am not getting anything when calling the Max function.Please advise!
I had recently started learning C++,so bear with me!
#include <iostream>
#include <cstring>
using namespace std;
struct book
{
char author[50];
int number;
};
void input_info(book *m,int n)
{
for (int i=0;i<n;i++)
{
cin.ignore();
cout<<"Enter author's name: " << endl;
cin.getline(m[i].author,50);
cout<<"Enter the number of books written:" << endl;
cin>>m[i].number;
}
}
int Max(book *m, int n)
{
int max=m[0].number;
for(int i=0;i<n;i++)
if(m[i].number>max)
max=m[i].number;
return max;
}
int main()
{
book s[100];
int i,n;
do
{cout<<"Number of authors(up to 20):";
cin>>n;
}while (n<1||n>5);
input_info(s,n);
Max(s,n);
return 0;
}