Okay guys, sorry if this is a bad submission but my first part of the homework is to return the largest of a, b, c. Here is my code so far... I have two solutions but I don't know if I'm doing this correctly.
#include <string>
#include <cassert>
#include <iostream>
usingnamespace std;
// Returns the largest of a, b, c.
int maximum(int a, int b, int c)
{
// EDIT HERE
int a = 0;
int b = 0;
int c = 0;
for (int x = 1; x < 100; x++)
{
cin >> a;
if (a > b);
{
b = a;
cout << "The largest number is: " << b << endl;
}
if (b > c)
{
c = b;
cout << "The largest number is: " << c << endl;
}
else
cout << "The largest number is: " << a << endl;
}
/*
cout << "Input a number for a: ";
cin >> a;
cout << "Input a number for b: ";
cin >> b;
cout << "Input a number for c: ";
cin >> c;
if ((a > b && a > c))
{
cout << "The largest is: " << a << " A";
}
if ((b > a && b > c))
{
cout << "The largest is: " << b << " B";
}
if ((c > a && c > b))
{
cout << "The largest is: " << c << " C";
}*/
return 0;
}
Okay, I came up with something like this, but I don't know why it's giving me an error for int a, b, and c? It says "redefinition of formal parameter 'a' 'b' and 'c'.
#include <string>
#include <cassert>
#include <iostream>
usingnamespace std;
// Returns the largest of a, b, c.
int maximum(int a, int b, int c)
{
// EDIT HERE
int a;
int b;
int c;
cout << "Input a three numbers: ";
cin >> a >> b >> c;
if (a >= b) {
if (a >= c)
{
cout << "The largest is: " << a << endl;
}
else
{
cout << "The largest is: " << b << endl;
}
}
else {
if (b >= c)
{
cout << "The largest is: " << b << endl;
}
else
{
cout << "The largest is: " << c << " C";
}
}
return 0;
}