This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
using namespace std; | |
int main() | |
{ | |
double a, b, c, x; | |
char num1, num2, num3; | |
cout << "ax+b=c의 x를 구합니다." << endl; | |
cout << "a의 값을 입력해주세요." << endl; | |
do{ | |
cin >> num1; | |
if(!isdigit(num1)) cout << "숫자만 입력해주세요." << endl; | |
}while(!isdigit(num1)); | |
a=atof(&num1); | |
cout << "b의 값을 입력해주세요." << endl; | |
do{ | |
cin >> num2; | |
if(!isdigit(num2)) cout << "숫자만 입력해주세요." << endl; | |
}while(!isdigit(num2)); | |
b=atof(&num2); | |
cout << "c의 값을 입력해주세요." << endl; | |
do{ | |
cin >> num3; | |
if(!isdigit(num3)) cout << "숫자만 입력해주세요." << endl; | |
}while(!isdigit(num3)); | |
c=atof(&num3); | |
if(a==0) | |
{ | |
if(b!=c){cout << "불능입니다." << endl;} | |
else{cout << "부정입니다." << endl;} | |
} | |
else | |
{ | |
x=(c-b)/a; | |
cout << "x의 값은 " << x << endl; | |
} | |
return 0; | |
} |