IceStorm wrote: |
---|
I'm sick of seeing this line of code in every single thread! Please update to a more recent compiler. |
My advice to you would be, learn to give advice and politely recommend possible compilers rather than making a comment saying they need to update it. Unless otherwise stated you should always approach new users as complete beginners who may not know anything outside of what some outdated book or site may be teaching them.
@shrutika
As
keskiverto pointed out you need to use code tags to help us read your code easier. As
IceStorm pointed out, your code tells us you are using a compiler that is outdated (I'm guessing Bloodshed's Dev-C++ (comes with the old MinGW compiler of that time) -- which Bloodshed's Dev-C++ hasn't been updated since the first quarter of 2005). There is a gentleman who started updating Dev-C++ elsewhere that I would recommend getting instead --
http://orwelldevcpp.blogspot.com/ .
The things that make it obvious that you are using an outdated compiler is the header files (
#include <iostream.h>
) that end with .h, but newer compilers no longer require .h (ie
#include <iostream>
) for standard header files (user created headers require the .h at the end. The other thing, as
IceStorm pointed out, is
void main()
because the C/C++ standards say main should return int
int main()
. Now embedded systems use
void main()
, but that is another topic altogether.
Lastly, I'd find a new learning source for learning C++ because if it is having you use that code, then it is also outdated. I'd recommend reading the tutorials on this site (
http://www.cplusplus.com/doc/tutorial/ ), maybe invest in books like Programming: Principles and Practice Using C++ 2nd Edition, C++ Primer (not to be confused with C++ Primer Plus), The C++ Standard Library Tutorial and Reference, and The C++ Programming Language (purely as a reference to the language). Above all else, program and practice, always practice.
Now as for your code:
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void upper(char []);
void lower(char []);
void non(char []);
void words(char []);
int main()
{
int choice = 0; // changed to int so your switch works
char ch = ' ', str[50];
cout<<"*****MENU*****";
cout<<"\n1.No. of capital alphabets\n2.No. of small alphabets\n3.No. of non-alphabets\n4.No. of Words";
cout<<"\nenter choice:";
cin>>choice;
cin.ignore(1, '\n');
cout<<"enter a string:";
cin.getline(str, 50);
switch(choice)
{
case 1: upper(str);
break;
case 2: lower(str);
break;
case 3: non(str);
break;
case 4: words(str);
break;
default: cout << "wrong choice\n";
break;
}
cin >> ch; // just to make it hold, enter a character and press enter to close
return 0;
}
void upper(char ch[])
{
int count=0;
for(int i=0;ch[i]!='\0';i++)
if(isupper(ch[i]))
count++;
cout<<"No. of capital alphabets:"<<count;
}
void lower(char ch[])
{
int count=0;
for(int i=0;ch[i]!='\0';i++)
if(islower(ch[i]))
count++;
cout<<"No. of small alphabets:"<<count;
}
void non(char ch[])
{
int count=0;
for(int i=0;ch[i]!='\0';i++)
if(!isalpha(ch[i]))
count++;
cout<<"No. of non-alphabets:"<<count;
}
void words(char ch[])
{
int count=1;
for(int i=0;ch[i]!='\0';i++)
if(ch[i]==' ')
count++;
cout<<"No. of words:"<<count;
}
|