Reputation: 1
I got my code here and I have tried to run it in visual studio a couple times and it keeps saying that "uninitialized local variable 'userNum' used" at line 10 but when I run it on the online c++ compiler, it runs just fine. Can you guys help me with this?
#include <iostream>
using namespace std;
int main() {
int userNum;
int i = 0;
int min;
cout << "Please enter your number: ";
while (userNum != 0) {
cin >> userNum;
if (i == 0) {
min = userNum;
}
else {
if (userNum < min && userNum != 0) {
min = userNum;
}
}
i++;
}
cout << "Smallest: " << min;
return 0;
}
Upvotes: 0
Views: 30
Reputation: 1048
int userNum
What you are doing here is declaring a variable but not initializing a value to it. Then you try to use this uninitialized variable in your while statement. Whatever the online compiler says, this is not good practice.
Change this statement to int userNum = (some value)
Upvotes: 3