Lab 1_ANSWER_SHEET hazimi.docx - FAKULTI TEKNOLOGI...

This preview shows page 1 - 4 out of 7 pages.

FAKULTI TEKNOLOGI KEJURUTERAAN ELEKTRIK & ELEKTRONIK UNIVERSITI TEKNIKAL MALAYSIA MELAKA COMPUTER PROGRAMMING BETR1343 SEMESTER 2 SESSION 2017/2018 LAB 1: PROGRAMS ON SELECTION CONTROL TECHNIQUES ANSWER SHEETS Section 1: if statement 3. Compile and run your program, and complete the table below: Input Value Output Statement 7 The number is positive -5 The number is negative 0 The number is zero 3.5 The number is positive Output for input value of 7:
Image of page 1

Subscribe to view the full document.

4. From the table above, what happens when input value is '0'? Why does this happen? Answer: The output will show no answer since it is not program for value of zero because zero is neither negative nor positive integer. 5. Modify the program so that it displays "The number is zero" if input is '0'. Copy and paste your program code. #include <iostream> using namespace std; int main() Output for input value of -5: Output for input value of 0: Output for input value of 3.5:
Image of page 2
{ int inputVal; //declare a variable (integer) cout << "Enter a number: "; cin >> inputVal; if (inputVal < 0) { cout << "The number is negative." << endl << endl;
Image of page 3

Subscribe to view the full document.

Image of page 4
  • Spring '14
  • Switch statement

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern