Codelab excercise 2- computer programming part 1

AI Thread Summary
The discussion focuses on a homework assignment involving basic programming tasks, including variable swapping, conditional expressions, and control structures. Participants emphasize the importance of attempting the problems independently before seeking help, adhering to forum rules. There is a suggestion to post one problem at a time to facilitate better assistance. The original poster expresses a willingness to comply with the rules and seeks guidance for the more challenging tasks. Overall, the conversation highlights the need for self-effort in learning programming concepts.
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
Views
3K
Replies
1
Views
12K
Replies
7
Views
3K
Replies
40
Views
8K
Replies
2
Views
3K
Back
Top