Question

C++ Write a program which accepts a character from the user. If the character is between...

C++

Write a program which accepts a character from the user. If the character is between 0 and 9, it will output that it's a digit. If the character is lowercase it will output that its a lowercase character. If it's an uppercase character it will output that it's uppercase. For all other cases it will output that it's neither a digit nor a letter. As an example of the output:

   Enter a digit or a letter: A
   You entered an uppercase character.

Homework Answers

Answer #1
#include<iostream>
using namespace std;

int main() { 
   char ch;
   cout<<"Enter a digit or a letter: ";
   cin>>ch;
   
   if(ch >='0' && ch <='9'){
      cout<<"You entered a digit"<<endl;
   }
   else if(ch >='A' && ch <='Z'){
      cout<<"You entered an uppercase character."<<endl;
   }
   else if(ch >='a' && ch <='z'){
      cout<<"You entered an lowercase character."<<endl;
   }
   else{
      cout<<"You entered neither a digit nor a letter."<<endl;
   }
   return 0;
}

Know the answer?
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
Similar Questions
C++ Write a program which accepts a numeric test score from the user. It will output...
C++ Write a program which accepts a numeric test score from the user. It will output the letter grade to the user corresponding to the score. Assume no “minus grades” (an A ranges from 90-100, B ranges from 80-89, C ranges from 70-79, D ranges from 60-69 and F is everything else.) Ensure that the score remains in the range of 0 to 100. As an example of the output: Enter your numeric grade and I will tell you your...
Write an assembly program which asks user to enter a character from ‘A’ to ‘Z’. If...
Write an assembly program which asks user to enter a character from ‘A’ to ‘Z’. If the user enters any other character, the program asks user to enter the character again. In this way the program inputs 300 characters and stores it in memory location from address $1000 to $112B. Hint: Use CPU register Y as counter
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
C++ [Program-2] Write a program that accepts an indefinite set of numbers until the user enters...
C++ [Program-2] Write a program that accepts an indefinite set of numbers until the user enters “-1”. In other words, the program keeps accepting new values until the user provides a “-1” (your program accepts all values, and discards the “-1”). When done, the program prints back to the user: (i) the sum of all numbers entered (except -1), (ii) the minimum value seen across all numbers (except -1), and (iii) the maximum value across all numbers (except -1).
Write a function that accepts a line of text and a single letter as input (case...
Write a function that accepts a line of text and a single letter as input (case insensitive) and returns the number of times the letter is the first character of a word. Note your program should be able to handle different cases. And check if the user input is a single letter. Example: Input text = "When the SUN rises at dawn, the chicken flies into the window." Input letter = "t" Output = "The letter t has appeared 3...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
In Python only. Write a program that prompts the user to enter a hex character and...
In Python only. Write a program that prompts the user to enter a hex character and displays its corresponding decimal integer.
IN JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
Provide Python code that does the following: 4) Write a program that asks the user to...
Provide Python code that does the following: 4) Write a program that asks the user to enter a 9 character password. Test to see if it is a valid password. The validity test is a) they enter exactly 9 characters AND b) that every 3rd character, starting with the 1st character is the letter z. If it is valid print out the message “valid password” otherwise print the message “invalid password”. Sample output. Please enter a password: zaazbbz12 valid password...
Write a program that plays a number guessing game with a human user. The human user...
Write a program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.