#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
void main(void)
{
char title[80];
int i=0;
int k=0;
int len=0;
int numSpacesLeft=0;
int numSpacesRight=0;
puts("\n\t\t\tCalculator Menu\n");
puts("\n\t\t1)\tPSI to BAR\n");
puts("\n\t\t2)\tBAR to PSI\n");
puts("\n\t\t3)\tTime from Distance and Speed\n");
puts("\n\t\t4)\tPower from Volt and Amps\n");
puts("\n\t\t5)\t555 Timer\n");
puts("\n\t\t6)\tExit the package\n");
printf("\nSelect an option from the above menu:\n");
scanf("%d",&k);
switch(k)
{
case 1: puts("PSI to BAR\n"); k=1;break;
case 2: puts("BAR to PSI\n"); k=2;break;
case 3: puts("Time from Distance and Speed\n"); k=3; break;
case 4: puts("Power from Volt and Amps\n"); k=4; break;
case 5: puts("555 Timer\n"); k=5; break;
case 6: puts("Exit the package\n"); k=6; break;
default: puts("Error please select the correct key\n"); break;
}
gets(title);
len=strlen(title);
numSpacesLeft=(80-strlen(title))/2;
numSpacesRight=80-numSpacesLeft;
for(i=0;i<numSpacesLeft;i++)
{
printf(" ");
}
printf("*");
for(i=0;i<len;i++)
{
printf("*");
}
printf("*");
for(i=0;i<numSpacesRight;i++)
{
printf(" ");
}
printf("\n");
for(i=0;i<numSpacesLeft;i++)
{
printf(" ");
}
printf("*");
printf("%s",title);
printf("*");
for(i=0;i<numSpacesRight;i++)
{
printf(" ");
}
printf("\n");
for(i=0;i<numSpacesLeft;i++)
{
printf(" ");
}
printf("*");
for(i=0;i<len;i++)
{
printf("*");
}
printf("*");
for(i=0;i<numSpacesRight;i++);
{
printf(" ");
}
do{
printf("\n\n\\n\nPress any key to continue");
getch();
}
while(k>6);
getch();
}
Using a do while loop for the program to operate continuously until the exit option is selected. As each option is selected a new screen should be displayed showing the title of the option selected and output on the screen in a box positioned at the canter of the screen in asterisks.When a key is pressed the original menu should be displayed again ready for the user's next selection......... HOW do I get it to accept a string instead of a decimal interger.

New Topic/Question
Reply



MultiQuote





|