Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.