Hi, this is my first time posting here. I'm in my first semester of c++ class. My HW assignment says:
Have user enter positive integers and keep track of the largest one. User can type -99 to quit.
Ex: "Enter a positive integer (-99 to quit)"
...user enters a positive number
"Enter another positive integer (-99 to quit)"
...user enters another one and so on until entering -99
"The largest number you entered is: "
I'm having trouble grasping how to make use of the sentinel value.
Here's the code I tried to make which I'm pretty sure is wrong... actually I am sure it's wrong lol.
#include <iostream>
usingnamespace std;
int main()
{
int x = 0;
int y = 0;
cout << "Enter a positive integer (-99 to quit): " << x << endl;
cin >> x;
cout << "Enter another positive integer (-99 to quit): " << x << endl;
cin >> x;
while (int != -99; int i = 0; i<100; i++)
{
cin >> x;
if (x>y)
y = x;
}
cout << "The biggest number is: " << y << endl;
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int x = 0;
int y = 0;
cout << "Enter a positive integer (-99 to quit): " << x << endl;
cin >> x;
cout << "Enter another positive integer (-99 to quit): " << y << endl;
cin >> y;
while (x != -99, x = 0, x < 100, x++);
{
cin >> x;
if (x>y)
y = x;
}
cout << "The biggest number is: " << y << endl;
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int x = 0;
int y = 0;
cout << "Enter a positive integer (-99 to quit): ";
cin >> x;
while (x != -99)
{
if (x>y)
y = x;
cout << "Enter another positive integer (-99 to quit): ";
cin >> x;
}
cout << "The biggest number is: " << y << endl;
return 0;
}