Shut down Computer in C++ programming by using the system() function to shut down the computer. system() function takes one string parameter, the parameter will be the path of the shutdown file.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char ch;
cout<<"Do you want to shutdown your computer now (y/n)"<<endl;
cin>>ch;
if(ch == 'y' || ch == 'Y') //if 'ch' value Equal to 'y' OR 'Y' then
{
system("C:\\WINDOWS\\System32\\shutdown /s"); //Shutdown Computer.
}
getch();
}