#include // The unit price of a microcontroller depends on the // number purchased: // // - If fewer than 10 are purchased, the unit price // is $12.75. // // - If between 10 and 99 are purchased, inclusive, // the unit price is $10.15. // // - If 100 or more are purchased, the unit price // is $9.75. // // Write a program that asks the user for the number of // microcontrollers being purchased and calculates the // total cost. // // Perform all calculations using integer numbers of // cents rather than dollars. When displaying the result, // however, print the total cost in dollars and cents. // // For example, a total cost of 12345 cents should be // displayed as // // $123.45 // // If the user enters a negative number of // microcontrollers, immediately terminate the program // by returning 0 from main(). // Function declarations int main(); // Function definitions int main() { return 0; } // Here is one solution: /* int main() { int amount_sold{}; std::cout << "Enter the number of microcontrollers sold: "; std::cin >> amount_sold; if ( amount_sold < 0 ) { return 0; } // Calculate the total cost in cents. int total_cost{}; if ( amount_sold < 10 ) { total_cost = 1275*amount_sold; } else if ( amount_sold < 100 ) { total_cost = 1015*amount_sold; } else { total_cost = 975*amount_sold; } // Integer division by 100 gives the number of // whole dollars. std::cout << "The total cost is $" << (total_cost/100) << "."; // The remainder after division by 100 gives the // number of cents. total_cost %= 100; // Exactly two digits must be printed for the cents. if ( total_cost == 0 ) { std::cout << "00" << std::endl; } else if ( total_cost < 10 ) { std::cout << "0" << total_cost << std::endl; } else { std::cout << total_cost << std::endl; } return 0; } */