The problem is as follows: On the student CD you will find a file named text.txt
ID: 3622082 • Letter: T
Question
The problem is as follows:
On the student CD you will find a file named text.txt. Write a program that reads the file's contents and determines the following:
* The number of uppercase letters in the file
* The number of lowercase letters in the file
* The number of digits in the file
* The number of whitespace characters in the file
* The number of punctuation marks in the file
There is an answer listed for this but it doesn't compile. There is a run-time error that sates that The variable 'c' is being used without being initialized.
I was wondering if you could rework this with explinations. I want to learn this which is why I would like to see explinations.
Thanks for your time.
This is what was listed for an answer but doesn't compile:
#include
#include
using namespace std;
int main()
{ ifstream in;
char c;
int up=0,low=0,d=0,white=0;
in.open("text.txt");
if(in.fail())
{ cout<<"file did notopen please check it ";
system("pause");
return 1;
}
while(in)
{if(isupper(c))
up++;
else if(islower(c))
low++;
else if(isdigit(c))
d++;
else if(isspace(c))
white++;
in.get(c);
}
cout<<"Uppercase characters:"system("pause");
return 0;
}