my teacher wants us to do this 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<int>(c);
x now has the value of 65
heres the code i have so far but im stuck how do i make them add together like he wants? im lost please help me. its due tonight
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
|
Put the#include <iostream>
#include <stdio.h>
#include <ctype.h>
using namespace std;
int main()
{
int i = 0;
int x = 65;
char str[] = "Test string.\n";
char c;
cout << "enter two upper case chars" << endl;
cin >> x;
}
void sumconstants()
{
char c = 'A';
int x = static_cast<int>(c);
}
code you need help with here.
|