I am trying to create a program that takes in 3 numbers and puts them in ascending order.
I have written out the code out but I keep getting an error saying:
"Error C4700 uninitalized local variable "num2" used.
"Error C4700 uninitialized local variable "num3" used.
I've done If/if-else/else nesting before but I've never ran into this error. I am new to C++ and still learning.
I've tried setting the variables to 0 for default and then asking in for a number so it will be overwritten and then I can compare them to each other. And I also get a random run-time error as well when I do not set them to 0;
Here is the code:
#include <iostream>
using namespace std;
int main()
{
int num1; //I get an error message when I do not set it to 0.
int num2;
int num3;
cout << "Please enter three numbers: " << endl;
cin >> num1; num2; num3;
if (num1 > num2 && num2 > num3){
cout << "In ascending order: " << num1 << num2 << num3 << endl;
}
else if (num2 > num1 && num1 > num3)
{
cout << "In ascending order: " << num2 << num1 << num3 << endl;
}
else if (num3 > num1 && num1 > num2){
cout << "In ascending order: " << num3 << num1 << num2 << endl;
}
else
{
cout << "There was an invalid input." << endl;
}
system("pause");
return 0;
}