Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

How Can I Make My Computer Shutdown With This Code In C

Here is the code i wrote it makes my computer log out and restart but not shut down (windows 7)

include <stdio.h>

include <conio.h>

int main() { int ch; printf("Type shutdown To shutdown The Computer: "); scanf("%d",&ch); switch(ch) { case 1:system("shutdown -s"); break; case 2:system("shutdown -l"); break; case 3:system("shutdown -r"); break; case 4:system("shutdown -v"); break;

case 5:exit(1); break; default:printf("Invalid choice"); } getch(); return 0; }

3 Answers

Derek Etnyre
Derek Etnyre
20,822 Points

Perhaps windows is performing some maintenance or installing some updates before it shuts down. What happens if you let your computer just do its thing for awhile at the point where it should be shutting down?

It is logging of but not shutting down

and sometimes restarts intead of shutting down.