Looping Help

How would you write a program that allows a user to continue to use the program as long as the person doesn't enter, for example, 'f' to finish?
here's my attempt:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter number or press 'f' to finish: ";
cin >> number;
while(number != 'f')
 {
   cout << "Number entered is " << number;
   cout << "Enter number or press 'f' to finish: ";
   cin >> number;
 }
return 0;
}


I don't think this is right, help is greatly appreciated!
You're writing a char into an int.

Take your input as a string instead.

Check if it is equal to "f", quit if true, otherwise, convert it to a number with std::stoi.

http://www.cplusplus.com/reference/string/stoi/
Topic archived. No new replies allowed.