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 a number in feet, converts it to meters, and displays the result. One foot is 0.305 meter.

Write a program that prompts the user to enter the min- utes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days

Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.