I am going to be upfront this is for a homework assignment. I have been online and found I could've made this so much easier just making an array but I am stubborn and want this to work with the original code.
Basically I am tasked with making a series of numbers then have the greatest number being the output after I cancel the program. The professor requires that the variables are clear for grading purposes that is why I am using variables max and number.
My issue is I cannot figure out the code to find that largest number or how to force it to recognize the that max>number. If you have an article for me to read I would love to find it because my book doesn't give much guidance and the things I have found online are in reference to arrays or a series of like 3-5numbers. If it is a simple fix that is awesome too but would still like to read about the logic.
#include <iostream>
using namespace std;
int main()
{
int number, max=0;
cout << "Enter a series of numbers and this program will find the largest. \n"
<< "Enter 0 will terminate the sequence of input values \n";
cout << "enter a number: ";
cin >> number;
while (number !=0)
{
cout << "enter a number: ";
cin >> number;
if (number < 0)
{
cout << "that is invalid enter a positive number \n";
}
}
if (number >= max=0)
number=max;
cout << "the largest number is: \n" << max;
return 0;
}
int max;
int number;
cout<<"Enter number: ";
cin>>number;
max = number;
while(number != 0)
{
cin>>number;
if(number > max)
max = number;
}
cout<<"The max is "<<max<<endl;
#include <iostream>
usingnamespace std;
int main()
{
int number = 0;
int max = 0;
cout<<"Enter 0 to stop\n\n";
cout<<"enter number: ";
cin>>number;
max = number;
while(number != 0)
{
cout<<"Enter number: ";
cin>>number;
if(number > max)
max = number;
}
cout<<"The max is: "<<max<<endl;
cin.ignore();
return 0;
}
oh so I have to input the greatest value statement inside the while statement brackets? along with the condition that if it is less than 0 to input a new response? lol last question (I sadly cannot compute this because I am leaving the lab and about to head to class) does this allow for an infinite number of integers to be input and it'll pick the largest?