This is some homework I am trying to figure out what I did wrong to be honest I am very new to programing and I am doing a horrible in class and so I am turning here in hopes that someone can point me in the right direction.
the code does fine while I am just entering a positive number it continuously loops as it is supposed to then when I enter a negative number to stop the code other lines pop up that are not supposed to be there and I really can not for the life of me figure out how to get my code to reference the positive number after I have entered a negative number to end the program. I know I have a lot of issues sorry for asking but any help would really make my day Thank you for taking your time to look at it.
#include <iostream>
usingnamespace std;
int main()
{
bool first = true;
short minimum;
short input;
cout << "This program will find the minimum positive number input. " << endl;
cout << " Entering a negative number will stop the input." << endl;
cout << " Please enter a positive number (negative number to quit):" << endl;
cin >> minimum;
while (minimum >= 0)
{
if (first = true)
{
if (minimum >= 1)
{
cout << " Please enter a positive number (negative number to quit):" << endl;
cin >> minimum;
input = minimum;
first = false;
}
else
{
cout << " 0 is not a valid input." << endl;
cout << " Please enter a positive number (negative number to quit):" << endl;
cin >> minimum;
}
}
else
{
if (minimum >= 1)
{
if (input < minimum)
{
input = minimum;
}
}
else
{
cout << " 0 is not a valid input." << endl;
cout << " Please enter a positive number (negative number to quit):" << endl;
cin >> minimum;
}
}
}
if (minimum <= -1)
{
cout << "No minium number was Input." << endl;
}
else
cout << " the minium number Input was " << input << endl;
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int minimum;
int number;
cout << "This program will find the minimum positive number input. " << endl;
cout << " Entering a negative number will stop the input." << endl;
cout << " Please enter a positive number (negative number to quit):" << endl;
cin >> number;
minimum = number; // this is our first input, and thus it is, so far, the minimum
while(number > 0) // enter loop if first number entered was positive
{
cin >> number; // get next number
if(number <= 0) break; // if next number is negative or 0 , break out of the loop
if(number < minimum) // if the next number entered (positive) is less than the minimum so far
minimum = number; // make it the new minimum
}
cout << "The minimum positive input was: " << minimum << endl;
}
This program will find the minimum positive number input.
Entering a negative number will stop the input.
Please enter a positive number (negative number to quit):
5
4
3
7
2
6
3
-5
The minimum positive input was: 2