#include<iostream>
#include <stdlib.h>
#include<conio.h>
using namespace std;
void a(int&,int&,int&,int[]);
void menu();
int main() {
int Temp_Disp = 0;
int Temp_Ad_Value[10];
int Average_Temp;
int S = 0;
int sw;
menu();
cout << " \n\n Switch OFF: ";
cin >> sw;
if (sw == 0) {
Temp_Disp = 0;
cout << " Nhiet do hien thi = " << Temp_Disp << endl;
}
else {
cout<<" Nhap sai!"<<endl;
exit(0);
}
menu();
cout << "\n\n Last switch OFF, current switch ON: ";
cin >> sw;
if (sw == 1) {
a(Temp_Disp,Average_Temp,S,Temp_Ad_Value);
Temp_Disp = Average_Temp;
cout << " Nhiet do hien thi = " << Temp_Disp << endl;
}else {
cout<<" Nhap sai!"<<endl;
exit(0);
}
S = 0;
do{
menu();
cout << "\n\n Last switch ON, current switch ON: ";
cin >> sw;
if (sw == 1) {
a(Temp_Disp,Average_Temp,S,Temp_Ad_Value);
if (Average_Temp > Temp_Disp) {
Temp_Disp++;
cout << " Nhiet do hien thi = " << Temp_Disp << endl;
}
if (Average_Temp == Temp_Disp) {
cout << " Nhiet do hien thi = " << Temp_Disp << endl;
}
if (Average_Temp < Temp_Disp) {
Temp_Disp--;
cout << " Nhiet do hien thi = " << Temp_Disp << endl;
}
}else {
cout<<" Nhap sai!"<<endl;
exit(0);
}
S = 0;
}while(1);
}
void menu(){
char chon;
cout<<endl<<endl;
cout<<" Nhan phim 0 de thoat !"<<endl;
cout<<" Nhan phim bat ky de tiep tuc !"<<endl;
cout<<" Select option: ";
chon = getche();
if(chon == '0')
exit(0);
}
void a(int &Temp_Disp, int &Average_Temp, int &S, int *Temp_Ad_Value ){
for (int i = 0; i < 2; i++) {
cout<<" Temp_Ad_Value["<<i<<"] :";
cin>>Temp_Ad_Value[i];
if(Temp_Ad_Value[i]>=0&&Temp_Ad_Value[i]<=255){}
else {
cout<<" Nhap sai!"<<endl;
exit(0);
}
S += Temp_Ad_Value[i];
Average_Temp = (S / 2);
}
cout<<" Nhiet do trung binh : "<<Average_Temp<<endl;
}
In ra các giá trị nhiệt độ từ sensor, thông qua nút switch c++
Bạn đang khoe hay bạn cần hỏi/giúp đỡ điều gì?
4 Likes