Menu
CoddyTech

Recap: Tiered Discounts

Lesson 26 of 48 in Coddy's C++ for Rust Developers course.

challenge icon

Challenge

Easy

Input: nonnegative unit price and quantity. Gross cost is price times quantity. Quantity at least 10 gets 20 percent off; at least 5 gets 10 percent off. Return discounted integer cost, truncating any fractional unit.

Implement the declared API in exercise.hpp and exercise.cpp. Both files are editable; preserve the public signatures. The locked main.cpp reads stdin and calls the API directly. It also checks public API behavior independently where stated. Return values rather than printing inside the API. Integer inputs and results fit signed int; text is ASCII unless stated otherwise.

Try it yourself

#include "exercise.hpp"
#include <iostream>
int main(){

std::vector<std::string> rows; std::string line; while(std::getline(std::cin,line)) rows.push_back(line);
std::istringstream in(rows.empty()?"":rows[0]);int p,q;in>>p>>q;std::cout<<discounted(p,q)<<"\n";
}

All lessons in C++ for Rust Developers

Practice on your own: Online C++ compiler