Lab 4

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

NAMA : IRFA IRSYA BINTI SUHAIZAN

NO MATRIC : BI22160523

ANSWER LAB 4
___________________________________________________________________________________
_________________________

PRACTICE 1 :

#include <iostream>
using namespace std;

int main()
{
const double highTempt = 102.5;
double tempt;
cout << "Enter the substance's Celsius temperature:>>";
cin >> tempt;

while (tempt > highTempt) {

cout << "The temperature is too high." << endl;


cout << "Turn the thermostat down and wait 5 minutes" << endl;
cout << "and enter it here: >> ";
cin >> tempt;
}

cout << "The temperatute is acceptable." << endl;


cout << "Check it again in 15 minutes." << endl;

return 0;
}

PRACTICE 2 :

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int score1, score2, score3;
double avg;
char testscore;

cout << "This program calculates the average of three test scores. " << endl;

do
{
cout << "Enter score #1 : ";
cin >> score1;
cout << "Enter score #2 : ";
cin >> score2;
cout << "Enter score #3 : ";
cin >> score3;

avg = (static_cast <double> ((score1 + score2 + score3) / 3.0));


cout << "The average is " << setprecision(4) << avg << "." << endl;

cout << "Would you like to average another set of test scores ? " <<
endl;
cout << "Enter Y for yes or N for no : ";
cin >> testscore;

} while (testscore == 'y' || testscore == 'Y');

return 0;
}

PRACTICE 3 :

#include <iostream>
using namespace std;

int main()
{
int number, multif = 1;

cout << "Enter an Integer : ";


cin >> number;

cout << "The entered Integer is : " << number << endl;

while (number != 0) {
multif = multif * (number % 10);
number = number / 10;
}
cout << "The multiplication of digit for this integer is :" << multif;

return 0;
}

PRACTICE 4 :

#include <iostream>
using namespace std;

int main()
{
cout << "ABC BANK AUTOMATIC TELLER MACHINE ATM\n";
cout << "============================================\n";

//variable declaration for user money


int b;
cout << "Enter withdraw amount : ";
cin >> b;

//variable declaration money


int b1 = 0;
int b2 = 0;
int b3 = 0;
int b4 = 0;
//process

while (b > 99) {


b = b - 100;
b1++;

while (b > 49) {


b = b - 50;
b2++;

while (b > 19) {


b = b - 20;
b3++;

while (b > 9) {
b = b - 10;
b4++;
}

//print
cout << "Number of 100 bills : " << b1 << endl;
cout << "Number of 50 bills : " << b2 << endl;
cout << "Number of 20 bills : " << b3 << endl;
cout << "Number of 10 bills : " << b4 << endl;

return 0;
}

You might also like