Programming Fundamentals CP Presentation
Programming Fundamentals CP Presentation
Fundamentals
Presented by:
Nayyab Afzal (23-PHY-11)
Saarina Irfan (23-PHY-4)
OUTLINE
Problem
Algorithm
Code
Output
Code explanation
Problem:
(4.15)
The first lines include the necessary libraries for input/output operations and output formatting.
The main function is the starting point of the C++ program.
double sales;
std::cin >> sales;
A variable sales is declared to store the input sales amount. The std::cin object reads from the
console, allowing the user to enter data.
while (sales != -1.0) {
This while loop keeps running as long as the sales variable is not -1.0. This
structure allows the program to process one salesperson's figures at a time.
std::cout << "[+] The earning is: $" << std::fixed << std::setprecision(2) <<
earning << "\n";
This line outputs the calculated earnings with two decimal places, using
std::fixed to fix the format and std::setprecision(2) to ensure two digits after the
decimal point.
return 0;
}
Once the user enters -1, the loop exits, and the program
returns 0, indicating successful execution.