In my program, I want to limit the amount of numbers a user can input using cin.getline(variable, N)
. My code looks like this (this is not the whole code):
#include <iostream>
int main()
{
input:
long double num1;
long double num2;
long double result;
char response;
cout << "Enter first number and then press enter" << endl;
cin >> num1;
cout << "Enter + to add, - to substract, * to multiply, / to divide, v to find the sqare root and ^ to find the power" << endl;
cin.getline(response, 2); //Here is the problem!
}
When I run this, I get the following error:
How can I store the value returned by cin
into a double
and a char
variable?
Please let me know if you want extra information.
UPDATE: I found a different solution for my project. The solution is specific to my code, and it won't work in other circumstances, so it's pointless to upload it. Thank you for your time.