Question
Write a function called sumConsonants that will take as arguments two upper case letters. Your function should return a sum of all the ascii values
Write a function called sumConsonants that will take as arguments two upper case letters. Your function should return a sum of all the ascii values of the consonants between the starting character and the ending character. Your main function should pass two values to the function and output the sum of all the consonant character values including the first and the last.
Required:
Your function must allow for either argument to be larger. For instance, passing A, C should yield the same as passing C, A.
You must also insure that the arguments to this function are upper case characters. If either argument is not you should return a -1 from the function;
It is best to use the isupper function see below.
You are allowed to use one decision (or two conditional statements) before the for loop to set the order of the characters.
You are allowed to use one decision before the for loop to determine the case of the characters.
You are allowed to use one decision inside the for loop to determine if the character is a vowel or consonant.
The order of the arguments must be taken care of prior to the beginning of the loop.
What not to do
Using any of the following will drop your grade for this assignment by 70%
global variables
cin in sumConsonants function
cout in sumConsonants function
goto statements
Note:
A char really is nothing more than an integer value. It is a short int value in between 0 and 255. What is different is how it is treated. Since you want to add a char to an int you will want to cast it:
char c = 'A';
int x = static_cast
x now has the value of 65
isupper function
/* isupper example */
#include
#includeYour program should look like the following CAWINDOWS system32\cmd.exe Enter two upper case chars The sum of the consonants betwee the two chars is 201 Press any key to continueint main() { int i=0; char str[]= "Test String. "; char c; while (str[i]) { c=str[i]; if (isupper(c)) c=tolower(c); cout << c << endl; i++; } return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started