Anda di halaman 1dari 5

#include <iostream> #include <iomanip> #include <fstream> #include <string> using namespace std;

int main() { cout << "Please enter 3 numbers"; double a,b,c; cin >> a >> b >>c; char choice; cout << endl << "(a) Display the maximum"; cout << endl << "(b) Display the minimum"; cout << endl << "(c) Display the numbers sorted in descending order"; cout << endl << "(d) Display the odd numbers"; cout << endl << "(e) Display the even numbers"; cout << endl << "(f) Write the numbers in a file"; cout << endl << "Please choose a number from the list"; cin >> choice;

switch (choice){ case 'a': case 'A': { double max=a; if (max<b || max<c)

{ max=b; if (max<c) max=c; } cout << setprecision(3) << showpoint <<max;

break; }

case 'b': case 'B': { double min; min=a; if (min>b || min>c) { min=b; if (min>c) min=c; } cout << setprecision(3) << showpoint << min <<endl; break;} case 'c': case 'C':{ if (a<b && b<c) cout <<setprecision(3) << showpoint <<c<<" "<<b<<" "<<a; else if (a<c && c<b) cout <<setprecision(3) << showpoint <<b<<" "<<c<<" "<<a; else if (b<a && a<c)

cout <<setprecision(3) << showpoint <<c<<" "<<a<<" "<<b; else if (c<a && a<b) cout <<setprecision(3) << showpoint <<b<<" "<<a<<" "<<c; else if (c<b && b<a) cout <<setprecision(3) << showpoint <<a<<" "<<b<<" "<<c; else if (b<c && c<a) cout <<setprecision(3) << showpoint <<a<<" "<<c<<" "<<b; break; } case 'd': case 'D': { int x,y,z; x=a; y=b; z=c;

if(!(x%2==0)) cout <<setprecision(3) << showpoint <<a << " "; if(!(y%2==0)) cout <<setprecision(3) << showpoint <<b<<" "; if(!(z%2==0)) cout <<setprecision(3) << showpoint <<c<<" ";

break;

case 'e': case 'E':{

int x,y,z; x=a,y=b,z=c; if((x%2==0)) cout <<setprecision(3) << showpoint <<a<< " "; if((y%2==0)) cout <<setprecision(3) << showpoint <<b<< " "; if((z%2==0)) cout <<setprecision(3) << showpoint <<c<< " "; break;}

case 'f': case 'F': { cout <<endl << "Give me a name for the file you want the numbers to be stored in" << endl; string fileName; cin >> fileName; ofstream File; File.open(fileName.c_str());

File <<setprecision(3) << showpoint <<a<< " "<<b<<" "<<c<<endl; File.close(); cout << "done";

int q; cin >> q; return 0; }

Anda mungkin juga menyukai