123456789101112131415161718192021222324252627282930313233343536373839404142
#include <iostream> #include <fstream> #include <string> using namespace std; char numerator1, denominator1, numerator2, denominator2, answer; int main (int argc, char *argv[]) { //Start to read picture string line; ifstream myfile ("picture.txt"); if (myfile.is_open()) { while (! myfile.eof()) { getline (myfile,line); cout << line << endl; } myfile.close(); } else cout << "Unable to open file"; //Finish reading picture //Output cout << "Enter your first ratio: "; cin >> numerator1; cin >> denominator1; cout << "Now your second ratio: "; cin >> numerator2; cin >> denominator2; if(numerator2="x"){ answer = numerator1 * denominator2 / denominator1; cout << answer; } }
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
#include <iostream> #include <fstream> #include <string> using namespace std; char numerator1, denominator1, numerator2, denominator2, answer; int main (int argc, char *argv[]) { //Start to read picture string line; ifstream myfile ("picture.txt"); if (myfile.is_open()) { while (! myfile.eof()) { getline (myfile,line); cout << line << endl; } myfile.close(); } else cout << "Unable to open file"; //Finish reading picture //Output cout << "Hello! Use 0 as the unknown variable." << endl; //Start loop char loop; do{ cout << "Enter your first ratio:" << endl; cin >> numerator1; cin >> denominator1; cout << "Now your second ratio:" << endl; cin >> numerator2; cin >> denominator2; cout << "Your unknown variable is "; //Formulas if(numerator1='x'){ answer = denominator1 * numerator2 / denominator2; } if(numerator2='x'){ answer = numerator1 * denominator2 / denominator1; } if(denominator1='x'){ answer = numerator1 * denominator2 / numerator2; } if(denominator2='x'){ answer = denominator1 * numerator2 / numerator1; } //Output answer cout << answer << "!"; //End Loop cout<< endl <<"Do you want to continue (Y/N)?" << endl; cin>>loop; }while(loop=='y'||loop=='Y'); if(loop=='n'){ cout << "Bye!" << endl; } }