I made a Newton-Raphson Method program. But I have a question. As you see, "epsilon" and "x0" are float type and when I try to write something like "a" or "b", the program goes crazy. I want to prevent it. I want to tell "Please enter a number" to the user when something happens like this.
Can you help me about that? Thank you.
Code is below:
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<locale.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include <iomanip>
#include<time.h>
#define f(x) pow(x,5)-pow(x,4)-pow(x,3)+2*pow(x,2)
#define g(x) 5*pow(x,4)-4*pow(x,3)-3*pow(x,2)+4*x
using namespace std;
int main()
{
setlocale(LC_ALL,"turkish");
cout << "Problem 4" << endl << "---------" << endl << "Verilen y=(x^2)/(x+1) ve y=(x^3)/(x^3+2) fonksiyonlarının varsa kesim noktalarını bulan C programı\n" << endl;
float x0, x1, f0, f1, g0, epsilon;
int tahmin = 1, sinir=1000;
cout << setprecision(6)<< fixed;
bastan:
cout << "Epsilon değerini giriniz: "; //Pay attention here. My question is about here.
epsilonHata:
cin >> epsilon;
cout << endl;
hata:
cout << "İlk tahmin değerini giriniz: "; //Just like above, my question is about here too.
cin >> x0;
cout << endl;
bla bla...
}