input three numbers and display largest one

Recommended Answers

All 2 Replies

42

> input three numbers and display largest one
Break it down into testing two numbers. Find the largest of the first two, then find the largest of that test and the third. Edward won't do your homework for you, but an example always helps. Here is some code that probably won't be accepted by a teacher but still solidifies the concept:

#include <iostream>

template <typename T>
T maximum(T a, T b)
{
  return a > b ? a : b;
}

int main()
{
  int a = 1;
  int b = 2;
  int c = 3;

  std::cout << maximum(maximum(a, b), c) << '\n';
}
Be a part of the DaniWeb community

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