Question: Using C++, Vidual Studio Code: // Program with some syntax errors, the math isn't quite right, and a // rather easy mistake to make in

 Using C++, Vidual Studio Code: // Program with some syntax errors,

Using C++, Vidual Studio

Code:

// Program with some syntax errors, the math isn't quite right, and a

// rather easy mistake to make in declaring the variables.

//

// 1/R-equiv = 1/R1 + 1/R2

//

// or

//

// R-equiv = ____1____

// 1/R1 + 1/R2

//

// Some correct answers:

// R1 and R2 both 10 ohms (using first formula):

// 1/r-equiv is 1/10 + 1/10 = 2/10, so R-equiv is 5 ohms

// R1 is 5 ohms and R2 is 10 ohms(using 2nd formula):

//R-equiv is 1/(1/5 + 1/10) = 1/(3/10) = 3.33333 ohms.

//-----------------------------------------------

#include

int main(void)

{

float r_equiv;

int R1, R2

cout

Prompt for resistence

cout

// read in resistor values.

cin >> r1, R2;

// while debugging, make sure we read in the correct resistences

cout >> "Resistors R1 and R2: "

// calculate the resistance:

r_equiv = 1 /

1 / R1 + 1 / R2;

cout

// for Windows folks running Visual Studio, the following lines

// stop the window from being closed when your program ends.

// These lines will have no effect for Mac folks using XCode.

#ifdef WIN32

system("pause");

#endif

return 0;

}

Hints:

forgot the double-slashes for several of the comments.

If you forget to tell it to use the standard namespace, it doesnt know what cin, cout or endl are.

Remember that for cin and cout, the double-arrows should point the direction you want the information to go.

So, for cout, you want the data to go to the console, so the arrows point towards cout. For cin, you want the data to come from the console and go to the variables, so the arrows should point towards the variables.

You need a double arrow for each variable, not a comma between variables. The comma in C++ is one of those operators that doesnt do what one might intuitively expect it to.

All variables must be declared before they can be used, and variable names are case sensitive. For example, abcd is not the same as Abcd.

When you get all the syntax errors fixed and you can compile and run the program, see if it gives the right answers for the sample test cases given in the comments. If not:

Check the data types being used!

Remember, integer and floating point arithmetic are different beasts in C++. You probably want R1 & R2 to be floats, not ints.

Also, think about operator precedence. You may need some parentheses to get the math

rt 3: Finding errors and debugging a program Sa for the red ngaigs's proklens Arit anl go fram ne

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!