I'm trying to make a simple program to state minimum and maximum of 3 numbers using nested if else statements I've got everything solved i think except when i try to output the values it says i haven't stated the variables minimum and maximum. i just started learning to program yesterday so I'm still very new. Please help thank you! Please note the code isn't properly indented when i post it on the website
#include <iostream>
#include <string>
using namespace std;
int main() {
char a, b, c;
cout << "Enter 3 numbers:";
cin >> a >> b >> c;
if(a >= b) {
if(a >= c){
if(b >= c){
double minimum = c;
double maximum = a;
}
else{
double minimum = b;
double maximum = a;
}
}
else{
double minimum = b;
double maximum = c;
}
}
else {
if( a >= c){
if(b >= c) {
double maximum = b;
double minimum = a;
}
The problem is that the variables minimum and maximum's scopes are inside of the if statements and will thus go away once they reach the end of their scope e.g. the end of the if statement. To fix this simply declare minimum and maximum outside of the if statements. And then instead of doing double minimum = "somevalue" inside of the if statement do minimum = "somevalue"