(Again a reminder that this language is still new to me )
I'm working on two programs, the first counts the number of vowels in a sentance inputed by the user, and uses a value returning function isVowel but I keep getting these two errors..
error C2065: 'ch' : undeclared identifier
error C2448: '<Unknown>' : function-style initializer appears to be a function definition
Am I missing something simple that I just can't see?
Code:
#include <iostream>
using namespace std;
int isVowel();
int main()
{
char ch;
cout << "Enter a sentence: ";
cin.get(ch);
return ch;
}
int isVowel(cin.get(ch))
{
char v;
int count;
count = 0, v = 0;
while (ch != '\n')
{
if(ch == 'A' || ch == 'a' || ch =='E' || ch == 'e'
|| ch == 'I' || ch == 'i' || ch == 'O' || ch == 'o'
|| ch == 'U' || ch == 'u')
count++;
v++;
}
cout << "There are" << v << "in this sentance" << endl;
return 0;
}
My second is supposed to determine an estimated population after a number of years from the current population, birth rate, death rate, and number of years inputed by the user using a growthRate funtion(birth, death), and an estimatedPopulation funtion(current pop, growth rate, and n) I managed to get past the 24 errors (lol I said I was new to this) but I still have 4 warnings about variables being used without being initialized, how do I correct this?
Code:
#include<iostream>
using namespace std;
int growthRate (int, int);
int estimatedPopulation (int, double, int);
int main()
{
int pop;
int birth;
int death;
int num;
cout << "Enter current population: ";
cin >> pop;
cout << "Enter birth rate: ";
cin >> birth;
cout << "Enter death rate: ";
cin >> death;
cout << "Enter the number of years for the projected population: ";
cin >> num;
return 0;
}
int growthRate(int birth, int death)
{
int pop;
int popgrowth;
if (pop > 2)
cout << "Population must be greater than 2 ";
if (birth > 0)
cout << "Birth rate must be a positive number";
if (death > 0)
cout << "Death rate must be a positive number";
popgrowth = birth - death;
cout << "Growth rate = " << popgrowth << "%" << endl;
return popgrowth;
}
int estimatedPopulation (int currentpop, int popgrowth, int num)
{
int pop;
int estpop;
int birth;
int death;
currentpop = pop + (birth * pop / 100) - (death * pop / 100);
estpop = currentpop * num;
cout << "Projected population after" << num << "years = " << estpop << endl;
return estpop;
}