I'm trying to make a program that "Tabulates", a formula to make simple graphics. The problem that I have is that some variables are not adding if they have a decimal point, that makes it run in an infinite loop, I want to fix this but I don't know how.
Here is the code:
#include <iostream>
//#include <conio.h>
#include <iomanip>
#include <limits>
//#include <ncurses.h>
using namespace std;
int main()
{
string formula;
float a;
float b;
float c;
float cantidad1;
float cantidad2;
float intervalo;
intervalo=1;
string signo;
cout << "Formula: y=ab+/-c\n";
cout << "Introduce el valor de a\n";
cin >> a;
//cout << "Introduce el valor de b\n";
//cin >> b;
cout << "Introduce el valor de c\n";
cin >> c;
cout << "Es suma o resta (responde con + o -)\n";
cin >> signo;
cout << "Del:";
cin >> cantidad1;
cout << "Al:";
cin >> cantidad2;
cout << "Intervalo:";
cin >> intervalo;
cout << "x|y\n";
cout << "----\n";
b=cantidad1;
while(cantidad1 <= cantidad2){
float res1 = 0;
if(signo=="-"){
res1 = a*b-c;
b=b+intervalo;
cantidad1= cantidad1+intervalo;
};
if(signo=="+"){
res1 = a*b+c;
b=b+intervalo;
cantidad1= cantidad1+intervalo;
};
cout<< b << "|" << res1 << "\n";
};
}
And besides that i would like to add a "Press any key to continue", but the methods that I've tried getch()
didn't work.