0% found this document useful (0 votes)
4 views2 pages

C++ Loop Program Solutions

The document contains C++ loop programs for various assignments, including a parking fee system, load-shedding countdown, water tank filling, savings account balance, and temperature alert system. Each program demonstrates the use of loops to perform specific tasks based on user input. The examples illustrate basic programming concepts such as conditionals and iterations.

Uploaded by

momnarajpoot52
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

C++ Loop Program Solutions

The document contains C++ loop programs for various assignments, including a parking fee system, load-shedding countdown, water tank filling, savings account balance, and temperature alert system. Each program demonstrates the use of loops to perform specific tasks based on user input. The examples illustrate basic programming concepts such as conditionals and iterations.

Uploaded by

momnarajpoot52
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C++ Loop Programs - Assignment Solutions

1. Parking Fee System


#include <iostream>
using namespace std;

int main() {
int hours;
while (true) {
cout << "Enter hours parked (0 to stop): ";
cin >> hours;
if (hours == 0) break;
cout << "Fee: " << hours * 50 << endl;
}
}

2. Load-Shedding Countdown
#include <iostream>
using namespace std;

int main() {
int minutes;
cout << "Enter remaining minutes: ";
cin >> minutes;

while (minutes >= 0) {


cout << minutes << endl;
minutes--;
}
}

3. Water Tank Filling


#include <iostream>
using namespace std;

int main() {
int water = 0;

while (water < 100) {


cout << "Water level: " << water << " liters" << endl;
water += 5;
}
cout << "Tank Full!" << endl;
}

4. Savings Account Balance


#include <iostream>
using namespace std;

int main() {
int deposit, balance = 0;

while (balance < 5000) {


cout << "Enter amount to deposit: ";
cin >> deposit;
balance += deposit;
}

cout << "Target reached! Balance = " << balance << endl;
}

5. Temperature Alert System


#include <iostream>
using namespace std;

int main() {
int temp;

while (true) {
cout << "Enter room temperature: ";
cin >> temp;

if (temp >= 22 && temp <= 25) break;

cout << "Adjust AC" << endl;


}
}

You might also like