- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ Program to find out the total price

Suppose, we have gone to a shop to buy three items. We have to buy two items of each kind. We have to buy items of prices b and d, but there is a choice between buying items of prices a and c. We buy the lowest priced item between a and c. Find out the total of the items we have purchased, an extra amount of 2 is added to the total for tax purposes. Multiply it by two, and print the total price.

## Problem Category

Various problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first, and to do that we have to study the particular problem in detail. A recursive approach can be used if there is a recurring appearance of the same problem over and over again; alternatively, we can use iterative structures also. Control statements such as if-else and switch cases can be used to control the flow of logic in the program. Efficient usage of variables and data structures provides an easier solution and a lightweight, low-memory-requiring program. We have to look at the existing programming techniques, such as Divide-and-conquer, Greedy Programming, Dynamic Programming, and find out if they can be used. This problem can be solved by some basic logic or a brute-force approach. Follow the following contents to understand the approach better.

So, if the input of our problem is like a = 10, b = 20, c = 15, d = 12, then the output will be 88.

## Steps

To solve this, we will follow these steps −

e := (if a < c, then a, otherwise c) print( 2 * (e + b + d + 2))

## Example

Let us see the following implementation to get better understanding −

#include<bits/stdc++.h> using namespace std; void solve(int a, int b, int c, int d) { int e = a < c ? a : c; cout<< 2 * (e + b + d + 2); } int main() { int a = 10, b = 20, c = 15, d = 12; solve(a, b, c, d); return 0; }

## Input

10, 20, 15, 12

## Output

88

- Related Articles
- Python Program to find out the price of a product after a number of days
- C++ code to find out the total amount of sales we made
- C++ Program to find winner and final price in a second price auction event
- C++ Program to find out the total cost required for a robot to make a trip in a grid
- Find out the minimum number of coins required to pay total amount in C++
- C++ Program to find out the health of a character
- Program to Find Out the Minimum Parsing Tree in C++
- C++ program to find out the maximum value of i
- C++ Program to find out the maximum rated parts set
- Program to find out the total number of characters to be changed to fix a misspelled word in Python
- Program to Find Out the Best Interval to Remove in C++
- Program to find total mutation group of genes in C++
- C++ Program to find out the super vertices in a graph
- C++ Program to find out the cost to travel all the given coordinates
- Program to find out the data type of user input in C++