Hi guys,
Can anyone show me how to integrate a loop in to my program?
My program will open applications once typed however, i want to remove the need for all the 'if' statements.
Any help would be amazing.
Thank you,
Code:#include <stdio.h>
#include <windows.h>
int main() {
char input[100];
char name[20];
char option[10];
{
printf("Hello User, please enter your name:\n", name);
scanf("%s", name);
printf("Thank you, %s\n", name);
printf("What program would you like to open, %s?\n", name);
scanf("%s", input);
}
if (strcmp(input,"Google") == 0){
printf("Opening Google Chrome for you!\n");
ShellExecute(NULL, "open","chrome.exe",NULL,NULL,SW_SHOWNORMAL);
printf("Done!\n");}
if (strcmp(input,"Outlook") == 0){
printf("Opening Microsoft Outlook for you!\n");
ShellExecute(NULL, "open","Outlook.exe",NULL,NULL,SW_SHOWNORMAL);
printf("Done\n");}
if (strcmp(input,"Putty") == 0){
printf("Opening Putty for you!\n");
ShellExecute(NULL, "open","Putty.exe",NULL,NULL,SW_SHOWNORMAL);
printf("Done\n");}
//system("Start \"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"); This doesnt seem to work? Use shell Execute instead.
else {
printf("no program entered, please enter another program\n");
}
printf("Is there another program you would like to open? Yes/No\n");
scanf("%s", option);
if (strcmp(option,"Yes")== 0){
printf("Enter another program.\n");
scanf("%s",input);}
if (strcmp(input,"Google") == 0){
printf("Opening Google Chrome for you!\n");
ShellExecute(NULL, "open","chrome.exe",NULL,NULL,SW_SHOWNORMAL);
printf("Done!\n");}
if (strcmp(input,"Outlook") == 0){
printf("Opening Microsoft Outlook for you!\n");
ShellExecute(NULL, "open","Outlook.exe",NULL,NULL,SW_SHOWNORMAL);
printf("Done\n");}
if (strcmp(input,"Putty") == 0){
printf("Opening Putty for you!\n");
ShellExecute(NULL, "open","Putty.exe",NULL,NULL,SW_SHOWNORMAL);
printf("Done\n");}
else {
printf("Okay, thank you.\n");
}
return 0;
}