Microsoft Visual C# 7th Edition
ISBN: 9781337102100
Author: Joyce, Farrell.
Publisher: Joyce, Farrell.
1 A First Program Using C# 2 Using Data 3 Using Gui Objects And The Visual Studio Ide 4 Making Decisions 5 Looping 6 Using Arrays 7 Using Methods 8 Advanced Method Concepts 9 Using Classes And Objects 10 Introduction To Inheritance 11 Exception Handling 12 Using Controls 13 Handling Events 14 Files And Streams Chapter2: Using Data
Chapter Questions Section: Chapter Questions
Problem 1RQ Problem 2RQ Problem 3RQ Problem 4RQ: Assume that you have two variables declared as int var1=3; and int var2=8; Which of the following... Problem 5RQ: Assume that you have a variable declared as intvar1=3;. Which of the following would display X 3X?... Problem 6RQ: Assume that you have a variable declared as int varl=3;. What is the value of 22% var1? 21 7 1 0 Problem 7RQ: Assume that you have a variable declared as int var1=3; . What is the value of 22/var1? 21 7.333 7 1 Problem 8RQ Problem 9RQ: Assume that you have a variable declared as int var1=3; if var2=++var1, what is the value of var2? 2... Problem 10RQ: Assume that you have a variable declared as int var1=3;. If var2=var1++, what is the value of var2?... Problem 11RQ Problem 12RQ: Which of the following is not a C# comparison operator? = != == Problem 13RQ Problem 14RQ: Which of the following C# types cannot contain floating-point numbers? a. float b. double c. decimal... Problem 15RQ: Assume that you have declared a variable as double hourly = 13.00;.What will the statement... Problem 16RQ: Assume that you have declared a variable as double salary =45000.00;. Which of the following will... Problem 17RQ: When you perform arithmetic operations with operands of different types, such as adding an int and a... Problem 18RQ Problem 19RQ Problem 20RQ: Which of the following compares two string variables named string1 and s tring2 to determine if... Problem 1E: What is the numeric value of each of the following expressions, as evaluated by the C# programming... Problem 2E: What is the value of each of the following Boolean expressions? 54 3=3 2+45 6==7 2+4=6 3+4==4+3 1!=2... Problem 3E: Choose the best data type for each of the following, so that no memory storage is wasted. Give an... Problem 4E: In this chapter, you learned that although a double and a decimal both hold floating-point numbers,... Problem 5E: Write a C# program named InchesTOCentmeters that declares a named constant that holds the number of... Problem 6E Problem 7E: Write a C# program named ProjectedRaises that includes a named constant representing next years... Problem 8E: Convert the ProjectedRaises class to an interactive application named ProjectedRaisesInteractive.... Problem 9E: Malcolm Movers charges a base rate of $200 per move plus $150 per hour and $2 per mile. Write a... Problem 10E Problem 11E: Write a program named Eggs that declares four variables to hold the number of eggs produced in a... Problem 12E: Modify the Eggs program to create a new one named Eggslnteractive that prompts the user for and... Problem 13E: Write a program named MakeChange that calculates and displays the conversion of an entered number of... Problem 14E: Write a program named Testslnteractive that prompts a user for eight test scores and displays the... Problem 15E: Write a program named FahrenheitToCelsius that accepts a temperature in Fahrenheit from a user and... Problem 16E Problem 17E Problem 18E: Pig Latin is a nonsense language. To create a word in pig Latin, you remove the first letter and... Problem 1DE: Each of the following files in the Chapter.02 folder of your downloadable student files has syntax... Problem 1CP: In Chapter 1, you created two programs to display the motto for the Greenville Idol competition that... Problem 2CP Problem 17RQ: When you perform arithmetic operations with operands of different types, such as adding an int and a...
Related questions
Concept explainers
Need help with this, It's C Programming .
Transcribed Image Text: ### 3.8.1: If-else statement: Fix errors.
#### Instruction
Re-type the code and fix any errors. The code should convert non-positive numbers to 1.
```c
if (userNum > 0)
printf("Positive.\n");
else
printf("Non-positive, converting to 1.\n");
userNum = 1;
printf("Final: %d\n", userNum);
```
### Example Code with Syntax Errors
```c
#include <stdio.h>
int main(void) {
int userNum;
scanf("%d", &userNum);
if(userNum > 0)
printf("Positive.\n");
else
printf("Non-positive, converting to 1.\n");
userNum = 1;
printf("Final:%d\n", userNum);
return 0;
}
```
### Explanation
The above code has a logical and syntactic error. The `else` statement will always execute because the `userNum = 1;` line is not within the scope of the `else` block. To correct it, place braces `{}` around the `else` block.
### Correct Code
```c
#include <stdio.h>
int main(void) {
int userNum;
scanf("%d", &userNum);
if(userNum > 0) {
printf("Positive.\n");
} else {
printf("Non-positive, converting to 1.\n");
userNum = 1;
}
printf("Final:%d\n", userNum);
return 0;
}
```
### Error Messages
- **Failed to Compile:**
```
main.c:17:4: error: expected identifier or '(' before 'return'
17 | return 0;
| ^~~~~~
main.c:18:1: error: expected identifier or '(' before '}' token
18 | }
| ^
```
- **Explanation:**
The errors reported here suggest a missing syntax that should be addressed by using braces properly around the if-else statements.
### Additional Note:
Although the reported line number is in the uneditable part of the code, the error actually exists in your code. Tools often highlight errors at the end of the code block when the true issue lies within misused statements or blocks.
Process by which instructions are given to a computer, software program, or application using code.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Step 1: Algorithm of the program:
VIEW
Step 2: Source code of the program:
VIEW Step 3: Screenshot of the program:
VIEW
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images