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;
}
Re: Simple problem with struct and function 80 80

You are calculating the maximum value correctly, but you are forgetting to actually print it to the screen. The following should print your value.

cout << "The maximum value is" << Max(s,n) << endl;
Re: Simple problem with struct and function 80 80

Damn,i forgot the cout...
Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.