Language
C++
Compiler
gcc 12.1.0
Options
Warnings
Don't Use Boost
C++11
-pedantic
#include <iostream>
#include <vector>
using namespace std;
int main(){
bool isrunning {true};
vector <int> nums {10,10,10,10};
while (isrunning){
char choice {};
char throwaway{};
int numtoadd {};
cout<<"P - Print Numbers" << endl;
cout<<"A - Add a Number" << endl;
cout<<"M - display mean of the numbers"<<endl;
cout<<"S - display smallest number"<<endl;
cout<<"L - display largest number"<<endl;
cout<<"Q - Quit"<<endl;
cout<<"Enter your choice:"<<endl;
cin >> choice;
switch (choice)
{
case 'P' :
for(auto num:nums){
cout << num << "\n";
}
break;
case 'p' :
for(auto num:nums){
cout << num << "\n";
}
break;
case 'A':
cout << "Input an integer to add:" << endl;
cin >> numtoadd;
nums.push_back(numtoadd);
cout << numtoadd << " Added." << endl;
break;
case 'a':
cout << "Input an integer to add:" << endl;
cin >> numtoadd;
nums.push_back(numtoadd);
cout << numtoadd << " Added." << endl;
break;
case 'Q':
isrunning = false;
break;
case 'q':
isrunning = false;
break;
default:
cout<<"Illegal Input"<<endl;
break;
}
cout<<"Enter any number to continue."<<endl;
cin >> throwaway;
}
}
A
334
0
a
42
0
P
0
r
0
q
0
$ g++ prog.cc -Wall -Wextra -std=c++11 -pedantic
P - Print Numbers
A - Add a Number
M - display mean of the numbers
S - display smallest number
L - display largest number
Q - Quit
Enter your choice:
Input an integer to add:
334 Added.
Enter any number to continue.
P - Print Numbers
A - Add a Number
M - display mean of the numbers
S - display smallest number
L - display largest number
Q - Quit
Enter your choice:
Input an integer to add:
42 Added.
Enter any number to continue.
P - Print Numbers
A - Add a Number
M - display mean of the numbers
S - display smallest number
L - display largest number
Q - Quit
Enter your choice:
10
10
10
10
334
42
Enter any number to continue.
P - Print Numbers
A - Add a Number
M - display mean of the numbers
S - display smallest number
L - display largest number
Q - Quit
Enter your choice:
Illegal Input
Enter any number to continue.
P - Print Numbers
A - Add a Number
M - display mean of the numbers
S - display smallest number
L - display largest number
Q - Quit
Enter your choice:
Enter any number to continue.
Exit Code:
0