Hayır, ortalamayı hesapla dediğim zaman hep 3 göstermesini istiyorum. @Vavien. Rahatsız ettiysem kusura bakmayın, genelde çok yardımcı oldunuz eğer bakabilriseniz.
Teşekkür ederim C++ gerçekten sizin ve vavienin yardımları dokundu.
[CODE title="C++"]#include <iostream>
#include <vector>
using namespace std;
int main() {
char selection{};
vector<int> list{ 1, 2, 3, 4, 5 };
int new_num{};
double average{};
double total {};
do {
cout << "Menu options: \n" << endl;
cout << "P - Print numbers\nA - Add a number\nM - Display mean of the numbers\nS - Display the smallest number\nL - Display the largest number\n" << endl;
cout << "Enter your choice: ";
cin >> selection;
if (selection == 'P' || selection == 'p') {
cout << "displaying all the elements in list: [ ";
for (int i = 0 ; i < 5; i++)
cout << list << " ";
cout << " ]" << endl;
}
else if(selection == 'A' || selection == 'a') {
cout << "Add integer: ";
cin >> new_num;
cout << "Adding new number to the list: [ ";
for (int i = 0 ; i < 5; i++)
cout << list << " ";
cout << new_num << " ]" << endl;
cout << "\n" << new_num << " added.\n" << endl;
}
else if (selection == 'M' || selection == 'm') {
cout << "\nCalculating average of the list... " << endl;
for (auto ttl: list) {
total += ttl;
}
average = total / list.size();
cout << "\nThe Average is: " << average << "\n" << endl;
}