Assignment 1

Write a program that inputs a Taiwan New Dollar (TWD) amount and then outputs as below (convert the input to $50, $10, $5, and $1 in order, and each conversion should be as much as possible).

Enter an amount of TWD: 123

The input corresponds to

NT $50: 2

NT $10: 2

NT $5: 0

NT $1: 3

  • More input-output samples.

    • Before sending assignments, make sure that your program passes the above input-output samples.

  • The input is assumed to be an integer with a size range from 0 to 999.

  • The following example is incorrect, because the conversion to $50 should be 2 rather than 1.

Enter an amount of TWD: 123

The input corresponds to

NT $50: 1

NT $10: 7

NT $5: 0

NT $1: 3

  • The outputs of your program should be exactly the same as those in the input-output samples.

    • Every output character (spaces, newlines, punctuation, and letters) of your program should be identical to those in the input-output samples.

    • It is recommended that you modify the code template to complete this assignment.

    • It is recommended that you use the text editor to open input-output samples and copy the outputs of your program to the same file. In this way, it is easy to verify whether the outputs of your program are identical to those in input-output samples.

    • Do not modify the string enclosed by double quotes, and do not output extra spaces or line breaks.

      • cout << "NT $50: " << variable2 << endl; // code template

      • cout << "NT $50:" << variable2 << endl; // Ex1

      • cout << "NT $50: " << variable2; // Ex2

      • cout << "NT $50: " << variable2 << endl; system("pause"); // Ex3

      • cout << "NT $50: " << variable2 << endl; cout << endl; // Ex4

      • Ex1 is incorrect, because it removes a space from the string enclosed by double quotes.

      • Ex2 is incorrect, because it removes endl.

      • Ex3 is incorrect, because it outputs extra line breaks caused by system("pause").

      • Ex4 is incorrect, because it outputs extra endl.

    • Suggestions:

      • Rename variable1~variable5 to meaningful names

        • For example, you can rename variable1 to amount_twd or amountTWD.

      • Remove comments

        • Typically, if your variable naming is meaningful, you need not to write comments.

  • Be sure to use the integer type (not floating-point) throughout your code for this assignment.