hello guys..
i'm so new and dumb, and i can't figure out why this is wrong. i did it exactly the way i saw it in the video and it not working. all i get is it pops up, asks me to type a number, but after typing number it goes away rlly quick. but i need it to sqrt that number first and stay there. i thought cin.get() make it stay but it wont let me
#include "stdafx.h"
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
double num1;
cout << "Pick your number bro..." << endl;
cin >> num1;
double num2;
num2 = sqrt (num1);
cout << "The square root of " << num1 << " is " << num2 << endl;
cin.get();
return 0;
}
I don't remember exactly how this works, but I thought it was just get(). If that doesn't work, and don't count on it working, then try #include <cstdlib> and replace cin.get(); with system("pause");. This is considered by some as bad practice, but you will probably be able to find better ways as you proceed.
EDIT: I believe that the function you are looking for is getch(). I haven't tested it because I use other methods, but that probably works.
what compiler are you using btw? If you are using visual studio you can set a flag (in linker settings?) to let the compiler know that you would like the console to remain open after the return 0; statement.
I think the problem is the cin.get() is getting your '\n' character when you hit enter. Maybe use another cin.get() (or, more ideally in this case, cin.ignore())?