Contoh Program C++ Mencari Nilai Maksimum dan Minimum
Selamat [], Terimakasih buat kunjungan Anda. Hari ini saya akan Posting Program C++ tentang Mencari Nilai Maksimum dan Minimum.
Baiklah langsung saja ke Program:
# include <stdio.h>
# include <iostream.h>
# include <conio.h>
void data ()
{
char nama[30], namaMax[30], namaMin[30];
float high,highMax=0.0, highMin=300;
float weight,weightMax=0.0, weightMin=400;
float ideal, idealMax=0.0, idealMin=150;
char anymore;
clrscr();
cout <<"Welcome to the C++ Programm. Do you want to\n";
cout <<"Looking for the Ideal Weight ?\n";
cout <<"Please Input Your Correct Data below\n";
anymore='Y';
while(anymore=='Y')
{
cout << endl <<endl;
cout << "Name = "; gets (nama);
cout << "High = "; cin >> high;
cout << "Weight = "; cin >> weight;
ideal=(high-100)*0.9;
if (high > highMax && weight > weightMax && ideal > idealMax)
{
strcpy (namaMax,nama);
highMax = high;
weightMax = weight;
idealMax = ideal;
}
if (high<highMin && weight<weightMin && ideal<idealMin)
{
strcpy (namaMin,nama);
highMin = high;
weightMin = weight;
idealMin = ideal;
}
cout <<" Do you have Any Datas ? ";
anymore=getche();
}
cout <<endl;
clrscr();
cout << endl << "Someone who have a Highest Ideal Weight Score\n"
<< "Name = " << namaMax << endl
<< "High = " << highMax << " cm"<<endl
<< "Weight = " << weightMax <<" Kg"<<endl
<< "Your Ideal Weight = " <<idealMax<<" Kg"<<endl;
cout <<endl;
cout << endl << "Someone who have a Smallest Ideal Weight Score\n"
<< "Name = " << namaMin << endl
<< "High = " << highMin <<" cm"<<endl
<< "Weight = " << weightMin <<" Kg"<< endl
<< "Your Ideal Weight = " <<idealMin<<" Kg"<<endl;
cout <<"\nPress Any Key to MAIN MENU";
getch();
}
main() // main program
{
char more=' ';
more='1';
while (more=='1')
{
clrscr();
cout << "MAIN MENU\n\n";
cout <<"Notification:\n";
cout <<"If You Press [1], You'll enter into a programm ideal-weight.\n";
cout <<"But If You Press [2],You'll going out from MAIN MENU to Coding.\n\n";
cout <<"Do you want to see Your Ideal-Weight ? \n\n";
cout <<"[1]. Yes\n";
cout <<"[2]. No\n";
cout <<"Input your choice = "; cin>>more;
if (more=='1')
data();
}
}
Baiklah langsung saja ke Program:
# include <stdio.h>
# include <iostream.h>
# include <conio.h>
void data ()
{
char nama[30], namaMax[30], namaMin[30];
float high,highMax=0.0, highMin=300;
float weight,weightMax=0.0, weightMin=400;
float ideal, idealMax=0.0, idealMin=150;
char anymore;
clrscr();
cout <<"Welcome to the C++ Programm. Do you want to\n";
cout <<"Looking for the Ideal Weight ?\n";
cout <<"Please Input Your Correct Data below\n";
anymore='Y';
while(anymore=='Y')
{
cout << endl <<endl;
cout << "Name = "; gets (nama);
cout << "High = "; cin >> high;
cout << "Weight = "; cin >> weight;
ideal=(high-100)*0.9;
if (high > highMax && weight > weightMax && ideal > idealMax)
{
strcpy (namaMax,nama);
highMax = high;
weightMax = weight;
idealMax = ideal;
}
if (high<highMin && weight<weightMin && ideal<idealMin)
{
strcpy (namaMin,nama);
highMin = high;
weightMin = weight;
idealMin = ideal;
}
cout <<" Do you have Any Datas ? ";
anymore=getche();
}
cout <<endl;
clrscr();
cout << endl << "Someone who have a Highest Ideal Weight Score\n"
<< "Name = " << namaMax << endl
<< "High = " << highMax << " cm"<<endl
<< "Weight = " << weightMax <<" Kg"<<endl
<< "Your Ideal Weight = " <<idealMax<<" Kg"<<endl;
cout <<endl;
cout << endl << "Someone who have a Smallest Ideal Weight Score\n"
<< "Name = " << namaMin << endl
<< "High = " << highMin <<" cm"<<endl
<< "Weight = " << weightMin <<" Kg"<< endl
<< "Your Ideal Weight = " <<idealMin<<" Kg"<<endl;
cout <<"\nPress Any Key to MAIN MENU";
getch();
}
main() // main program
{
char more=' ';
more='1';
while (more=='1')
{
clrscr();
cout << "MAIN MENU\n\n";
cout <<"Notification:\n";
cout <<"If You Press [1], You'll enter into a programm ideal-weight.\n";
cout <<"But If You Press [2],You'll going out from MAIN MENU to Coding.\n\n";
cout <<"Do you want to see Your Ideal-Weight ? \n\n";
cout <<"[1]. Yes\n";
cout <<"[2]. No\n";
cout <<"Input your choice = "; cin>>more;
if (more=='1')
data();
}
}
Pranala --> C++ Program Mencari Nilai Maximum dan Minimum (Notifikasi)
ReplyDelete