Errors in program

Which of the following are errors in the following program? An error may be syntax, logic, or even style (indention,
spacing, identifiers, etc.).

1
2
3
4
#include<iostream>
using namespace std;int main(){int x,y,z;double w;cin>>
x;y=x/12;z=x%12;w=x/12.0;cout<<x<<’=’<<y<<’&’<<z<<’(’<<w<<’)’
<<endl;return 0;}


A) spacing is needed around operators
B) change int variables to double
C) add comments
D) make 12 a short constant
E) wrap any long lines properly
F) change single quotes to double quotes
G) prompt before cin
H) clean up labeling on results
I) typecast on w calculation
J) indent lines between { and }
K) void in main’s ()
L) blank lines between logical sections/at logical
breaks
M) fix variable names (it’s an inches conversion program)
N) change int variables to short or long
O) join last three lines and then break after ;, {, }, and
() of main

If the user enters 43, what will the program produce (as currently written)?
I believe it is A,B,C,D,F,J,L,M,N,O, but I am not 100% sure. I'm also not sure what entering 43 will give me.
B is impossible, it will be an error in z = x % 12;.
Definitely F
D is possible, but not need
C, E, O, J - style
A - not necessary, it works without spacing but looks nice with :-)

The only REAL error is F

43 = 3&7(3.58333)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>

using namespace std; 

int main()
{
	int x, y, z; 
	double w; 
	
	cin >> x; 
	y = x / 12; 
	z = x % 12; 
	w = x / 12.0; 
	cout << x << " = " << y << "&" << z << "(" << w << ")"<< endl; 
	return 0;
}


This is my version.
Is there a reason why the number in parentheses (3.58333) only haves 5 numbers after the decimal? Doesn't the data type double allow for 15 digits of precision?
Yes, it is because of 'cout', it has precision set to 6 digits. You can change this by using
cout.precision(). I.e. insert cout.precision(10) at the beginning of main() and you will see what happens.
Cool. Thanks
Topic archived. No new replies allowed.