Skip to content

Instantly share code, notes, and snippets.

@juanfal
Last active September 30, 2025 09:19
Show Gist options
  • Save juanfal/0ad059d9c81aac52b22d836f949ad3bf to your computer and use it in GitHub Desktop.
Save juanfal/0ad059d9c81aac52b22d836f949ad3bf to your computer and use it in GitHub Desktop.
version with previous to while price reading
// 31.mercadona.cpp
// juanfc 2025-09-29
// version with previous to while price reading
// https://gist.github.com/juanfal/0ad059d9c81aac52b22d836f949ad3bf
#include <iostream>
using namespace std;
int main()
{
float s = 0; // important initialization
int cnt = 0; // important initialization
cout << "New customer, enter prices (0 ends)" << endl;
float price; // do not initialise it
cin >> price; // the user will do it for you
float minPrice = price, maxPrice = price;
while (price != 0) {
if (price > maxPrice) {
maxPrice = price;
} else if (price < minPrice) {
minPrice = price;
}
s += price;
++cnt;
cin >> price;
}
if (cnt > 0) {
cout << "Total: " << s << endl;
cout << "Max price: " << maxPrice << endl;
cout << "Min price: " << minPrice << endl;
cout << "Avg price: " << s / cnt << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment