Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,026 questions

51,982 answers

573 users

How to find max in struct array using C++

1 Answer

0 votes
#include <iostream> 
#include <climits> 
 
using namespace std; 
   
struct Test { 
    float book_price; 
    int book_tax; 
}; 
   
int find_max(Test arr[], int len) { 
    int mx = INT_MIN; 
     
    for (int i = 0; i < len; i++) { 
        int tmp = arr[i].book_price + arr[i].book_tax; 
        mx = max(mx, tmp); 
    } 
    return mx; 
} 
   
int main() 
{ 
    Test arr[] = { 
        { 4, 6 }, 
        { 1, 7 }, 
        { 11, 5 }, 
        { 8, 6 }, 
        { 2, 3 }, 
        { 7, 5 } 
    }; 
     
    int result = find_max(arr, sizeof arr / sizeof arr[0]); 
     
    cout << result; 
     
    return 0; 
} 
 
 
 
/*
run:
 
16
 
*/

 



answered May 6, 2019 by avibootz

Related questions

1 answer 172 views
172 views asked May 6, 2019 by avibootz
1 answer 122 views
1 answer 148 views
1 answer 157 views
3 answers 106 views
...