Hint please!1

Can someone please give me a hint on how to code this question. This is a home-work question so hint only please!.

Pseudo code is an informal description of a sequence of steps for solving a problem. It can be used to help convert a problem from "human" language to "computer" language like C++.
find the minimum value from a series of user inputs.

Set a Boolean variable "first" to true.

While input value is not negative

If first is true

If input value is positive

Set the minimum to the input value.

Set first to false.

Else

Output 0 is not a valid input.

Else

If input value is positive

If the input value is less than the minimum

Set the minimum to the input value.

Else

Output 0 is not a valid input.



If first is true

Output no valid numbers were input so there is not a minimum value.

Else

Output the minimum value.




Last edited on
This is my code so far but I am definitely missing so can you tell me what..

#include <iostream>

using namespace std;

int main()
{
int first;
int num = 0;


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 >> first;

while (first > num)
{
cout << "Please enter a positive number (negative number to quit)" << endl;
cin >> first;

}

if(first == 0)
{
cout << "0 is not a valid input " << endl;
cout << "Please enter a positive number (negative number to quit)" << endl;
cin >> first;
}
if(first < 0)
{
cout << "No valid numbers were input, so there is no minimum value." << endl;
}



return 0;
}
Last edited on
Hello Taha001,

First a question, did you get the answer you wanted? This thread is marked as completed, not sure if that is what you wanted?

First line of your pseudo code says Set a Boolean variable "first" to true. yet you have made that an int in your code. And later the pseudo code says to set first to false. That works as long as you know that first will be zero.

The block that says if (first == 0) should be inside the while loop.

Last item: edit the code message and highlight the code and use the code button <> the the right to make your code easier to read and to give it line numbers.

Hopes that helps? Post your new code when you have more problems.

Andy
Topic archived. No new replies allowed.