I created a program that will find the biggest number when give 3 different numbers. But when I want to change the program to find the biggest number when you enter 4 integer number I continue to run into problems. I can get it to find the biggest number when you in put 3 numbers but when I try to do four it wont let me. Please help.

#include <iostream>
using namespace std;

int findbiggest(int, int, int);

int main()
{
    int x, y, z;
    cout << "Please input three integers "<< endl;
    cin>>x>>y>>z;
    cout<<"The biggest number is "<<findbiggest(x, y, z);
    return 0;
}

int findbiggest(int a, int b, int c)
{
    int bigger=0;
    if (a>b) bigger=a;
    else bigger=b;
    if (c>bigger) bigger=c;
    cout<<"The biggest number is "<<bigger<<endl;
    return bigger;
}

The code will read in three numbers:
cin>>x>>y>>z;
If you type in four numbers, the code doesn't change. It works the same. If you want to be able to enter four numbers, change the code to accept four numbers.

You might want to change the code so that you can enter as many numbers as you want. You don't want to have to change the code every time you want to enter more numbers, or do you?? Maybe you do, but I wouldn't. You can do that by using a while or do loop and ask for the numbers one at a time. Have the loop stop when you enter a specific number, such as -1.

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.