Question: Good use of whitespace. #include using namespace std; int main() { int myFirstVar; // Aligned comments yield less int yetAnotherVar; // visual clutter int thirdVar;

Good use of whitespace.

#include using namespace std;

int main() {

int myFirstVar; //

Aligned comments yield less int yetAnotherVar; // visual clutter int thirdVar;

// Above blank line separates variable declarations from the rest cout << "Enter a number: "; cin >> myFirstVar; // Note >> is under <<. Less visual clutter. // Above blank line separates user input statements from the rest yetAnotherVar = myFirstVar; // Aligned = operators thirdVar = yetAnotherVar + 1; // Also notice the single-space on left and right of + and = // (except when aligning the second = with the first =) cout << "Final value is " << thirdVar << endl; // Single-space on each side of << return 0; // The above blank line separates the return from the rest.

Figure 2.3.3: Bad use of whitespace.

#include  using namespace std; int main() { int numPeople; int totalOuncesPasta; cout<<"Enter number of people: ";cin>>numPeople; totalOuncesPasta = numPeople * 3; cout << "Cook " << totalOuncesPasta << " ounces of pasta." << endl; return 0;} 

Feedback?

PARTICIPATION

ACTIVITY

2.3.2: Whitespace.

Are the specified lines of code good or bad uses of whitespace?

#include  using namespace std; int main() { int userAge; int currentDecade; int nextDecade; int nextMilestone; cout << "Enter your age: " << endl; cin >> userAge; currentDecade=userAge/10; nextDecade = currentDecade + 1; nextMilestone = nextDecade * 10; cout << "Next big birthday is at " << nextMilestone << endl; return 0; } 

1)

int nextDecade;

Good

Bad

2)

currentDecade=userAge/10;

Good

Bad

3)

nextDecade = currentDecade + 1;

Good

Bad

4)

nextMilestone = nextDecade * 10;

Good

Bad

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!