fix programming error

Programming errors can be categorized into three types: syntax errors, runtime 
errors, and logic errors.
#Beginner
Runtime and logical error are difficult to identify.

In gcc c++ compiler using namespace std;



#include <iostream>
using namespace std;

int main()
{
float i = 17;
float j = 0;
cout << "runtime error 17/0 :" << i / j;
cout << endl;
cout << "logic error 17/7 :" << 17 / 7;
cout << endl;
cout << "fix logic error 17/7 :" << 17.0 /7;
return 0;
}
copy


Output

runtime error 17/0 :inf
logic error 17/7 :2
fix logic error 17/7 :2.42857
[Program finished]


Runtime error is zero can't dived any number.
Logic error are more difficult to identify in big calculation and big program to solve the error just apply type casting to fix error. In above example 17 divided by 7 is show int value when apply 17.0 divided by 7 the compiler identify the floating points is anser then they show 2.42857 .Best Sellers in Software

Need of Programmer

Need of Programmer

Comments

Popular posts from this blog

Write a program that reads in the radius and length of a cylinder and computes the area and volume using the following formulas: area = radius * radius * π volume = area * length

Write a program that prompts the user to enter two points (x1, y1) and (x2, y2) and displays their distance between them.The formula for computing the distance is

Area and perimeter of an equilateral triangle c++ program