Question

New instructions for this assignment. They want it to accept all types of uppercase/lowercase. and q...

New instructions for this assignment. They want it to accept all types of uppercase/lowercase. and q should be to quit. Want the use of switch case. Very very basic c program

Create an algorithm for a menu based program that uses a switch-case statement to include the following options:

a) Print your name.

b) Print your tutorial time.

c)  Prompt the user to enter a positive number between 1-50, read the entered input, and display all numbers from 0 up to the number entered (the display should print five numbers per line).

E.g: if the user enters 5, the program will display 0 1 2 3 4 5.

q) Quit

The user should be able to continuously enter and execute options until they enter the 'q' character to quit. The algorithm should be able to accept the upper- and lower-case versions of all character input options and should be able to deal with invalid options being input for all input (including the number required for part c).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
//variables
char name[50], choice;
//getting the name
printf("Enter your name: ");
scanf("%s",name);
//getting time
time_t current_time = time(NULL);
char* c_time_string;
c_time_string = ctime(&current_time);

//looping until user hits q
while(1){
printf("Choose an option\n");
printf("a) Print your name\n");
printf("b) Print your tutorial time\n");
printf("c) Enter a number between 1-50\n");
printf("q) Quit\n");
scanf("%s", &choice);//getting choice
switch(choice){
case 'a':
case 'A':
//printing name
printf("Your name is %s\n",name);
break;
case 'b':
case 'B':
//printing time
printf("Your tutorial time is %s\n",c_time_string);
break;
case 'c':
case 'C':
//getting and printing the numbers
printf("Enter the number: ");
int num;
scanf("%d", &num);
//checking for valid input
if(num<1 || num>50){
printf("Invalid Input\n");
}else{
for(int i=0;i<=num;i++){
printf("%d ", i);
}
}
printf("\n");
break;
case 'q':
case 'Q':
//quiting
return 0;
default:
printf("Invalid Input\n"); //in case of invalid input

}
}
return 0;
}

Sample Output:

Enter your name: Name
Choose an option
a) Print your name
b) Print your tutorial time
c) Enter a number between 1-50
q) Quit
a
Your name is
Choose an option
a) Print your name
b) Print your tutorial time
c) Enter a number between 1-50
q) Quit
b
Your tutorial time is Sun Mar 29 10:55:51 2020

Choose an option
a) Print your name
b) Print your tutorial time
c) Enter a number between 1-50
q) Quit
c
Enter the number: 45
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
Choose an option
a) Print your name
b) Print your tutorial time
c) Enter a number between 1-50
q) Quit
q

Add a comment
Know the answer?
Add Answer to:
New instructions for this assignment. They want it to accept all types of uppercase/lowercase. and q...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...

    Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To compile, build, and execute an interactive program with a simple loop, conditions, user defined functions and library functions from stdio.h and ctype.h. You will write a program that will convert characters to integers and integers to characters General Requirements • In your program you will change each letter entered by the user to both uppercase AND lowercase– o Use the function toupper in #include...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • in Python: •Flip case: Write a program to do the following: •Accept the input of a...

    in Python: •Flip case: Write a program to do the following: •Accept the input of a sentence from the user that contains lowercase, uppercase, and special characters. •Make a new sentence in which the lowercase characters are changed to uppercase and the uppercase are changed to lower case.   All other characters will retain their original value. Print the original sentence and the new sentence.

  • Java Switch Case Make From Pseudocode

    The following pseudo-code describes a menu-driven algorithm:loopask the user to input one of the characters a, b, c, d, e, q read in a character from the keyboardif the character is'a' output your name and your tutor's name (hard-coded) 'b' input 3 double numbers x, y, z and output the largestand the smallest of the three numbers'c' input 2 integer numbers m and n, and display all thenumbers between m and n (both inclusive) with five numbers per line (note...

  • Write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase...

    Write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase letters, digits, and punctuation. Output the results neatly formatted and labeled in columns. how I can make this program in a more simple way. # get user input user_string = input("Enter a sentence: ") # create and initialize variables upper_case = 0 lower_case = 0 digits = 0 spaces = 0 punctuations = 0 x = len(user_string) #loop conditions and increment for i in...

  • Prompt the user to enter two character strings. The program will then create a new string...

    Prompt the user to enter two character strings. The program will then create a new string which has the string that appears second, alphabetically, appended to the end of the string that shows up first alphabetically. Use a dash (-') to separate the two strings. You must implement the function string appendStrings(string, string), where the return value is the combined string. Display the newly created string. Your program must be able to handle both uppercase and lowercase characters. You are...

  • Array Class Assignment

    This is a two-part assignment. It is better to submit the files for both parts when you are done than to submit part 1 first and part 2 later.In the Array.h file includes the class definition and member functions implementations.PART 1Write And Test An Array Class [Array.TestDriver.cpp] Write a data structures class. The resulting class can be used in any program in place of a C++ array, in case you want the advantages of range safety and built-in size tracking.Requirements....

  • Write a C program that does the following: • Displays a menu (similar to what you...

    Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...

  • 10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string...

    10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT