so im having a bit of trouble with getting my program to run properly in xcode. the build succeeds (thats what xcode says) but as soon as a i enter my two resistances (youll see what i mean below), something goes wrong. so here is the code:
//"Resistance is Everything" program -- CS 121
using namespace std;
short res1; //declared first variable
short res2; //declared second variable
cout << "\t\t\tWelcome to the Resistor Calculation Program!!!";
cout << "\n\nPlease enter your two resistances: ";
cout << "\nThank you!! You have entered " << res1 << " ohms and " << res2 << " ohms." << endl << endl;
cout << "If your resistors are placed in series, they will total to " << series_total << " ohms." <<endl;
cout << "If your resistors are placed in parallel, they will total to " << parallel_total << " ohms." <<endl <<endl;
cout << "Thank you for using RCP. Have a wonderful day!";
cout << "\n\n"; //Included for cleaner look
when i enter "3 3" meaning my two resistors i have both have a value of 3 ohms, the program doesnt actually stop running, but in the output screen it says (11db). and also, it highlights the "parallel_total" equation in my program in green and next to it, it says "thread 1 exc_arithmetic (code=exc_i386_div subcode=0x0)"
can you guys help me out with this? i have no idea what it means.
when i change the data types for res1 res2 and series_total, to float the program runs perfectly fine. why isnt it running correctly for short? it should be shore if im correct
(res1+res2)/res1*res2 is equal to ((res1+res2)/res1)*res2 and is equals to ((res1+res2)*res2/res1).
Your program uses wrong logic.
And if you use (res1+res2)/(res1*res2) The problem with integer division still persist.