OK, I am having two issues right now. In the first program, I am trying to calculate the distance between two points. I think I have the right formula, but I am not sure. I am supposed to use the pow and sqrt functions, and I have tried. The output is something crazy.
As for my 2nd problem, I am having issues with if else statements. I am supposed to be making an error handler for an invalid rating( not equal to 1, 2 or 3)...I have tried to do so but I guess I am just not getting it. I am new to C++ as you can see. Please help in anyway possible:Code:#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { int x1; int x2; int y1; int y2; int d1; int d2; int d3; double distance; cout << "What is the x value for point 1?" << endl; cin >> x1; cout << "What is the y value for point 1?" << endl; cin >> y1; cout << "What is the x value for point 2?" << endl; cin >> x2; cout << "What is the y value for point 2?" << endl; cin >> y2; distance = sqrt(sqrt(x2-x1) + sqrt(y2-y1)); cout << distance << endl; system("pause"); return 0; }
Code:#include <iostream> #include <iomanip> using namespace std; int main() { double currentSalary ; //input by user double raise ; //calculated by program based on the rating double newSalary ; // calculated by the program;currentSalary + raise int rating ; // input by the user string employee ; // the name of the employee // initialize raise and newSalary raise =0; newSalary = 0; cout << " Enter the employee's name and press enter " ; getline ( cin, employee); cout << "Enter the current salary \t" ; cin >> currentSalary; cout << "Input a performance rating \n " "\t1 excellent \n\t2 good \n\t3 poor\n"; cin >> rating ; if (rating = 1) newSalary = .06 * currentSalary; cout << "New Salary: " << currentSalary << endl; cout << "Raise Amount: 6%" << endl; cout << "New Salary: " << newSalary << endl; if (rating = 2) newSalary = .04 * currentSalary; cout << "New Salary: " << currentSalary << endl; cout << "Raise Amount: 4%" << endl; cout << "New Salary: " << newSalary << endl; if (rating = 3) newSalary = .015 * currentSalary; cout << "New Salary: " << currentSalary << endl; cout << "Raise Amount: 1.5%" << endl; cout << "New Salary: " << newSalary << endl; if (rating != 1,2,3) cout << "Invalid rating" << endl; // Include if (if else) to calculate the raise and the new salary. //cout << fixed << showpoint<<setprecision(2); //cout << "\n\nEmployee name: " << employee ; //cout << "\ncurrent salary\t$"<< currentSalary; //cout << "\nraise \t$"<< raise <<" for performance rating " << rating ; //cout << "\nnew salary\t$"<< newSalary << "\n\n\n"; system("pause"); }




Reply With Quote