This is my code, and the error/warning is included.
0001 /*
0002 Randall Hall
0003 CSCE 1020.00
0004 Lab 5 - program 2
0005
0006 C program to display the largest & smallest of 5 integers
0007 */
0008
0009 #include <iostream>
0010
0011 int main() { _webcompErrorHandler(); // Added for webCompiler error handling
0012
0013
0014 double x, y, z, a;
0015 double Largest, Smallest;
0016
0017 cout << "CSCE 1020 Lab 5\t Randall Hall\t randallhall2@my.unt.edu\n";
0018
0019 cin >> x;
0020 cin >> y;
0021 cin >> z;
0022 cin >> a;
0023
0024 cout << "Enter number 1: " << x << endl;
0025 cout << "Enter number 2: " << y << endl;
0026 cout << "Enter number 3: " << z << endl;
0027 cout << "Enter number 4: " << a << endl;
0028
0029 if(x > y && x > z && x > a)
0030 x = Largest;
warning: 'Largest' may be used uninitialized in this function
0031
0032 if(y > x && y > z && y > a)
0033 y = Largest;
0034
0035 if(z > x && z > y && z > a)
0036 z = Largest;
0037
0038 if(a > x && a > y && a > z)
0039 a = Largest;
0040
0041 if(x < y && x < z && x < a)
0042 x = Smallest;
warning: 'Smallest' may be used uninitialized in this function
0043
0044 if(y < x && y < z && y < a)
0045 y = Smallest;
0046
0047 if(z < x && z < y && z < a)
0048 z = Smallest;
0049
0050 if(a < x && a < y && a < z)
0051 a = Smallest;
0052
0053 cout << "The largest value entered was " << Largest << endl;
0054 cout << "The smallest value entered was " << Smallest << endl;
0055 return 0;
0056
0057 }
HELP!! I am a new programmer and this is for my class. Would anyone also care to explain to me what the warning means?
it's supposed to take the value of x to be the largest until another value is introduced then take the larger of those two numbers and so on until it's done that for x, y, z and a
We haven't learned loops yet and I've already done the nested approach
but don't the way I have it structured saying that it recieves the value of all four numbers, then compares x to every other variable and if its true then set it to Largest?
but don't the way I have it structured saying that it recieves the value of all four numbers, then compares x to every other variable and if its true then set it to Largest?
No, it does not. Not remotely. What do you think Largest is? That's just the name you gave to a variable. You could have called it beansOnToast. You could have called it anything. The compiler won't guess what you meant to code based on names of variables.
compares x to every other variable and if its true then set it to Largest?
So, you thought that x would be set to Largest, and then at the end you don't even output x, but instead you output Largest? But you though x was going to be the biggest number?
The issue here is that, unfortunately, you simply don't understand how to program. Did you perhaps mean this?