232k views
0 votes
Write a program in C++.

Find the lowest price in C++.
1. Input number of items. {3
items}
2. Price of the item. {3 items}
3. Print the lowest price.
4. Total price using loop.

1 Answer

7 votes

Final answer:

To find the lowest price in C++, create an array to store the prices and iterate through it to identify the lowest price. Additionally, you can calculate the total price using a loop.

Step-by-step explanation:

To find the lowest price of the items, you can use an array to store the prices and then iterate through the array to find the lowest price. Here's a sample program in C++:

#include <iostream>

#include <climates>

using namespace std.

int main () {

int Num Items.

cout << "Enter the number of items: ".

cin >> Num Items.

int prices [Num Items].

cout << "Enter the prices of the items: ";

for (int i = 0; i < Num Items; i++) {

cin >> prices[i];

}

int lowest Price = INT_MAX.

for (int i = 0; i < Num Items; i++) {

if (prices[i] < lowest Price) {

lowest Price = prices[i].

}

}

cout << "The lowest price is: " << lowest Price << Endl.

int total Price = 0.

for (int i = 0; i < Num Items; i++) {

total Price += prices[i].

}

cout << "The total price is: " << total Price << Endl.

return 0.

}

User Haris Qurashi
by
7.8k points