Codelab excercise 2- computer programming part 1

Click For Summary

Discussion Overview

The discussion revolves around a homework assignment related to computer programming, specifically focusing on control structures and conditional statements in code. Participants are addressing various problems that require writing code to perform specific tasks, such as swapping values, evaluating conditions, and using control flow statements.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • Post 1 outlines multiple programming tasks, including swapping variable values and writing conditional statements based on given criteria.
  • Some participants express that the original poster (OP) needs to demonstrate more effort in attempting the problems before seeking help.
  • There is a suggestion to tackle one problem at a time rather than presenting multiple issues simultaneously.
  • The OP acknowledges the feedback and indicates a willingness to try the problems independently while still seeking assistance for the more challenging ones.

Areas of Agreement / Disagreement

Participants generally agree that the OP should make a serious attempt at the homework before asking for help. However, there is no consensus on how best to approach the problems, as the OP is still uncertain about some tasks.

Contextual Notes

The discussion highlights the importance of individual effort in learning programming concepts, but it does not resolve the specific coding challenges presented by the OP.

goku3240
Messages
4
Reaction score
0

Homework Statement



1) Given three already declared int variables, i , j , and temp , write some code that swaps the values in i and j . Use temp to hold the value of i and then assign j 's value to i . The original value of i , which was saved in temp , can now be assigned to j .

2) Given the variables temperature and humidity , write an expression that evaluates to true if and only if the temperature is greater than 90 and the humidity is less than 10 .
3) Given the integer variables yearsWithCompany and department , write an expression that evaluates to true if yearsWithCompany is less than 5 and department is not equal to 99 .
4)Given the variables isFullTimeStudent and age , write an expression that evaluates to true if age is less than 19 or isFullTimeStudent is true.
5) Write a conditional that assigns true to the variable fever if the variable temperature is greater than 98.6
6)
Write a conditional that decreases the variable shelfLife by 4 if the variable outsideTemperature is greater than 90 .
7)
Write a conditional that assigns 10,000 to the variable bonus if the value of the variable goodsSold is greater than 500,000 .
8) Write a conditional that multiplies the values of the variable pay by one-and-a-half if the value of the boolean variable workedOvertime is true.
9) Write an if/else statement that assigns true to the variable fever if the variable temperature is greater than 98.6 ; otherwise it assigns false to fever .
10) Write an if/else statement that compares the value of the variables soldYesterday and soldToday , and based upon that comparison assigns salesTrend the value -1 ( soldYesterday greater than soldToday ) or 1 .

11) Write an if/else statement that adds 1 to the variable minors if the variable age is less than 18 , adds 1 to the variable adults if age is 18 through 64 , and adds 1 to the variable seniors if age is 65 or older.
12)
Write an if/else statement that compares the double variable pH with 7.0 and makes the following assignments to the bool variables neutral , base , and acid :
false, false, true if pH is less than 7
false, true, false if pH is greater than 7
true, false, false if pH is equal to 7
13) Write a switch statement that tests the value of the char variable response and performs the following actions:
if response is y , the message Your request is being processed is printed
if response is n , the message Thank you anyway for your consideration is printed
if response is h , the message Sorry, no help is currently available is printed
for any other value of response , the message Invalid entry; please try again is printed





Homework Equations



the control structures if and else, true flase,

The Attempt at a Solution



the first i tried temp=i then j=temp and i switched up the variables but haven't good the right answer. all the other ones are the same i can't get the 1st few to understand the rest.
 
Physics news on Phys.org
Same comment as in your other thread: Per the forum rules, you need to make an effort at this yourself before getting help.
 
Mark44 said:
Same comment as in your other thread: Per the forum rules, you need to make an effort at this yourself before getting help.

KK thanks I just joined today, and I just read the rules. So i will try it out but will i reiceve help with the difficult ones?
 
Post 1 problem at a time, not 10 or a dozen, and show that you are making a serious attempt at writing the code for it. If you're still stuck, someone will steer you in the right direction.
 

Similar threads

  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 1 ·
Replies
1
Views
12K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 40 ·
2
Replies
40
Views
8K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 16 ·
Replies
16
Views
13K