My program works great, but I want to put the output in its own function as well (to keep int main() clean. When I set up the function output(), I try to send vCount to it. The problem is, the program doesn't even execute the output function now. This is probably a tiny mistake, but if someone could point it out, I'd appreciate it. :)
What is line 23 supposed to do? It actually assigns value of vCount to variable int output;
Also I do not see a reason why output() is returning int.
Try removing lines 21 and 23 and replace them with: output(countVowels(X));
We haven't learned about void in class yet, and we're not supposed to use it.
I understand that void is simply a function that doesn't return a value (research online), but for now, it's against class rules. Silly, I know.
To answer your question: Line 23 was supposed to call function output() and send the value "vCount" to it. int B (in function output) grabs vCount, and outputs the text. Obviously it didn't work like I thought it would. :)
Okay, I tidied up the code a bit, and I figured I'd share it with everyone who helped out so you can see how I did. Comments and critiques are welcomed and requested. =D
// ==========================
// Global Declarations
// ==========================
#include "stdafx.h"
#include <iostream>
#include <string>
usingnamespace std;
string input(); // Function: input
int countVowels( string ); // Function: countVowels
bool reRun(); // Function: reRun
int output( int ); // Function: output
// ==========================
// Function: main
// ==========================
int main(){
bool run = true;
while(run){
string X = input(); // Get Input
int vCount = countVowels(X); // Count Vowels
output(vCount); // Display Output
run = reRun(); // Loop Program
}
return 0;
}
// ==========================
// Function: input
// ==========================
string input(){
string Y;
cout << "Please type word: ";
cin >> Y;
cout << endl;
return Y;
}
// ==========================
// Function: countVowels
// ==========================
int countVowels(string Z) {
int NewCount = 0;
int L = 0;
while ( L < Z.length() )
{
char Let = Z [L];
bool isVowel (Let == 'a' || Let == 'e' || Let == 'i' ||
Let == 'o' || Let == 'u' || Let == 'A' ||
Let == 'E' || Let == 'I' || Let == 'O' ||
Let == 'U');
if ( isVowel == true ){
++NewCount;
}
++L;
}
return NewCount;
}
// ==========================
// Function: reRun
// ==========================
bool reRun() {
char run2;
cout << "Do you want to run this program again? (y/n): ";
cin >> run2;
cout << endl; cout << endl;
if ( run2 != 'y' || run2 != 'Y' )
returnfalse;
elsereturntrue;
}
// ==========================
// Function: output
// ==========================
int output(int B){
cout << "There are " << B << " vowels in your word.";
cout << endl; cout << endl;
return 0;
}
[P.S.: Mr. Derkacht, if you are checking to see if your students copied their code from a website and end up seeing this, please note that I (crystalgem) am one of your students, not someone that your students copied this code from. ;) ]