0

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;
}
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by coolbits
0

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;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.