Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to write a program which uses a While LOOP. you are to ask the user, thr

ID: 3596035 • Letter: Y

Question

You are to write a program which uses a While LOOP. you are to ask the user, through an InputBox, whether they want to enter a name or not (using YES/NO). For the first name, this should be outside the loop. All subsequent requests should be inside the loop.

You are to write a program which uses a While LOOP. You are to ask the user, through an InputBox, should be outside the loop. All subsequent requests should be inside the loop whether they want to enter a name or not (using YES/NO). For the first time, this You should use either the ToUpper or Tolower function to get the result from the user. Next, use a second InputBox to get the name from the user. This will be INSIDE the loop. We will assume that the user will always enter the names separated by a single space. You will then, for each name, parse out the first, middle, and last names and then write these to a ListBox. You will need to use the substring and length features of string variables. Here is a sample form and result: This program will ask you for two thing 2. The name, as in James Robert Innes

Explanation / Answer

Save this code in a file.c, compile and run.

Here stdin/stdout is used. You can modify the input/output port in your application.

Here is the sample output of the program

/******************************/

Do you want to enter a name? YES/NO YES
Enter the name Ned Edward Stark
Do you want to enter a name? YES/NO YES
Enter the name John Snow Targerian
Do you want to enter a name? YES/NO YES
Enter the name Tyrion Imp Lannester
Do you want to enter a name? YES/NO NO
First Name   Middle Name   Last Name
Ned       Edward       Stark
John       Snow       Targerian
Tyrion       Imp       Lannester

/****************************/

/*
* name.c
*
* Created on: 19-Oct-2017
*      Author:
*/
#include <stdio.h>
#include <string.h>
void ToUpper(char* name);

int main()
{
   printf("Do you want to enter a name? YES/NO ");
   char choice[4];
   fgets(choice,4,stdin);
   char name[60];
   char first[10][20];
   char middle[10][20];
   char last[10][20];
   int count=0;
   while(!strcmp(choice,"YES"))
   {
       getchar();
       printf("Enter the name ");
       fgets(name,60,stdin);
       setbuf(stdout,NULL);
       char* ptr=strtok(name," ");
       int i=0;
       while(ptr!=NULL)
       {
           if(i==0)
               strcpy(first[count],ptr);
           else if(i==1)
               strcpy(middle[count],ptr);
           else if(i==2)
               strcpy(last[count],ptr);
           i++;
           ptr=strtok(NULL," ");
       }
       count++;
       ToUpper(choice);
   }
   int i;
   printf("First Name Middle Name Last Name ");
   for(i=0;i<count;i++)
   {
       printf("%s %s %s",first[i],middle[i],last[i]);
   }

   return 0;
}

void ToUpper(char* choice)
{

   printf("Do you want to enter a name? YES/NO ");
   fgets(choice,4,stdin);
   setbuf(stdout,NULL);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote