Hi, all. I am new to this site and to C++ (and am struggling with it). I am getting ready to turn in my second assignment and have a question regarding one of my programs. I will provide as much info as I can.
I believe I have met the criteria for the program but I wanted to make it a little more error proof. Here goes:
Create an enumerated type with three values: POSITIVE,
NEGATIVE, and ZERO. Write a function that prompts the
user for an integer, reads the integer, and returns one
of the enumerated values based on that number (e.g., returns
NEGATIVE if the input number is < 0). Write a main function
that calls this function, and displays, using a "switch"
statement, what category of number was entered.
Example:
Please enter an integer: 6
The number you entered was positive.
My code...
#include "stdafx.h"
#include <iostream>
//Program "using" statements.
using namespace std;
int main()
{
status = get_Value();
switch (status)
{
case POSITIVE:
cout << endl << endl << "The number entered is Positve." << endl
<< endl;
break;
case NEGATIVE:
cout << endl << endl << "The number entered is Negative." << endl <<
endl;
break;
case ZERO:
cout << endl << endl << "The number entered is Zero." << endl << endl;
break;
default:
cout << endl << endl << "The value entered is not an integer value."
<< endl;
cout << "Enter an integer value.";
break;
}
return 0;
}
Value_status get_Value()
{
int value = 0;
cout << endl << endl << "Enter an integer value: ";
cin >> value;
if (value > 0)
{
return POSITIVE;
}
else if (value < 0)
{
return NEGATIVE;
}
else
{
return ZERO;
}
}
My program works based on the design criteria but if user input is a char value like "a" or "f", it outputs the "Zero" message instead of the "warning" message I thought it would. I also think I know why. The char values fall into the category of "else" every othe input == ZERO.
I can't figure out how to output the error message when a char value is entered. I could use some direction now.