# Difference: HandsOn2122 (1 vs. 3)

#### Revision 32017-01-24 - JimSkon

Line: 1 to 1

 META TOPICPARENT name="Spring2017"

# Hands on for Chapter 2.1 and 2.2

Line: 54 to 54
6. Assume that the typical bite of a candy bar is 0.7 ounces. Add code to display the number of bites per bar, and the total number of bites for all the bars. What types did you use? Why?
Changed:
<
<
7. A person burns (weight * .57) calories per mile walking, and (weight * .72) calories per mile running. Ask the persone for their weight, and tell them how many miles they would need to run or walk to burn off the bandy they re proposing to eat.
>
>
7. A person burns (weight * .57) calories per mile walking, and (weight * .72) calories per mile running. Ask the person for their weight, and tell them how many miles they would need to run or walk to burn off the candy they are proposing to eat.
8. Uninitialized Variables: Write a program that contains statements that output the value of five or six variables that have been declared, but not initialized. Compile and run the program. What is the output? Explain.

#### Revision 22017-01-24 - JimSkon

Line: 1 to 1

 META TOPICPARENT name="Spring2017"

# Hands on for Chapter 2.1 and 2.2

Line: 46 to 46
2. Now add a new variable calories_per_bar. What should be the type?
Changed:
<
<
3. Add an input prompt to get the calories. Ad an input statement to get a values or calories.
>
>
3. Add an input prompt asking the user to enter the number of calories per bar. Then add an input statement to get the number of calories.

Changed:
<
<
4. Add a statement to compute the total number os calories given the number of candr bars.
>
>
4. Add a statement to compute the total number of calories given the number of candy bars.
5. Print out the total number of calories along with an appropriate message.
Changed:
<
<
6. Assume that the typical bite of a candy bar is 0.7 ounces. Add code to display the number of bites per bar, and the total number of bites for all the bars.
>
>
6. Assume that the typical bite of a candy bar is 0.7 ounces. Add code to display the number of bites per bar, and the total number of bites for all the bars. What types did you use? Why?

Changed:
<
<
7. Uninitialized Variables: Write a program that contains statements that output the value of five or six variables that have been declared, but not initialized. Compile and run the program. What is the output? Explain.
>
>
7. A person burns (weight * .57) calories per mile walking, and (weight * .72) calories per mile running. Ask the persone for their weight, and tell them how many miles they would need to run or walk to burn off the bandy they re proposing to eat.

8. Uninitialized Variables: Write a program that contains statements that output the value of five or six variables that have been declared, but not initialized. Compile and run the program. What is the output? Explain.

#### Revision 12017-01-17 - JimSkon

Line: 1 to 1
>
>
 META TOPICPARENT name="Spring2017"

# Hands on for Chapter 2.1 and 2.2

1. Create a project and get the following program to run:

##### Candy bar calculations
`<-- SyntaxHighlightingPlugin -->`
```//DISPLAY 2.1 A C++ Program
#include <iostream>
using namespace std;
int main( )
{
int number_of_bars;
double one_weight, total_weight;

cout << "Enter the number of candy bars in a package\n";
cout << "and the weight in ounces of one candy bar.\n";
cout << "Then press return.\n";
cin >> number_of_bars;
cin >> one_weight;

total_weight = one_weight * number_of_bars;

cout << number_of_bars << " candy bars\n";
cout << one_weight << " ounces each\n";
cout << "Total weight is " << total_weight << "ounces.\n";

cout << "Try another brand.\n";
cout << "Enter the number of candy bars in a package\n";
cout << "and the weight in ounces of one candy bar.\n";
cout << "Then press return.\n";
cin >> number_of_bars;
cin >> one_weight;
total_weight = one_weight * number_of_bars;

cout << number_of_bars << " candy bars\n";
cout << one_weight << " ounces each\n";
cout << "Total weight is " << total_weight << " ounces.\n";

cout << "Perhaps an apple would be healthier.\n";

return 0;
}```
`<-- end SyntaxHighlightingPlugin -->`

2. Now add a new variable calories_per_bar. What should be the type?

3. Add an input prompt to get the calories. Ad an input statement to get a values or calories.

4. Add a statement to compute the total number os calories given the number of candr bars.

5. Print out the total number of calories along with an appropriate message.

6. Assume that the typical bite of a candy bar is 0.7 ounces. Add code to display the number of bites per bar, and the total number of bites for all the bars.

7. Uninitialized Variables: Write a program that contains statements that output the value of five or six variables that have been declared, but not initialized. Compile and run the program. What is the output? Explain.

Copyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback