When I reach case 2 and type "n" my complier prints out my cout statement but just continues running until the end of the program. I commented out a few statements to make sure that it actually did run till the end. What am I doing wrong?
Also i'm not really worried about the math so you don't really have to check that. I just want to get it working properly before I deal with the logic errors.
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
double x1,x2,y1,y2,slope;
int choice;
cout<<"Type one of the following numbers "<<endl;
cout<<"1. Are you trying to find the slope ?"<<endl;
cout<<"2. Are you trying to find the y intercept ? "<<endl;
cout<<"3. Are you trying to find the x intercept ? "<<endl;
cin>>choice;
switch (choice) {
case 1:
cout<<"Enter the points you would like to find the slope for "<<endl;
cin>>x1>>y1;
cout<<"Enter the other set of points "<<endl;
cin>>x2>>y2;
slope=(y2-y1)/(x2-x1);
cout<<"Your slope is "<<slope<<". In other words m="<<slope<<"x"<<endl;
break;
case 2:
double slope, b;
int y;
cout<<"Enter you slope (as a decimal if it's a fraction) "<<endl;
cin>>slope;
cout<<"Do you know more than one point? (x,y) is one point. If so type y for yes and n for no. "<<endl;
cin>>y;
if (y=='n' || y=='N')
{
double x1,y1;
cout<<"Enter the point you know "<<endl;
cin>>x1>>y1;
b=(((slope*x1)-y1)*(-1));
//cout<<"Your y-int is "<<b<<endl;
}
else
{
cout<<"Enter the points you know "<<endl;
cin>>x1>>y1>>x2>>y2;
b=(((slope*x1)-y1)*(-1));
//cout<<"Your y-int is "<<b<<". b="<<b<<endl;
}
}
return 0;
}
Characters cannot be stored in integers - you're putting the standard input stream into an error state and so all subsequent read operations are ignored. On line 27 use char instead of int.