C++ program
User need to enter first name , last name in C++ program, the name length will be calculated for each character later output will be displayed on screen
first name : umar$
last name : javed$
Note: what is $ this symbol i wrote in code to remind program that its end of character for name
Output
code : //programmingisbest.blogspot.com
User need to enter first name , last name in C++ program, the name length will be calculated for each character later output will be displayed on screen
first name : umar$
last name : javed$
Note: what is $ this symbol i wrote in code to remind program that its end of character for name
Output
code : //programmingisbest.blogspot.com
- #include<iostream>
- #include<conio.h>
- using namespace std;
- //programmingisbest.blogspot.com
- void main()
- {//programmingisbest.blogspot.com
- char fname[15],lname[15];
- cout<<"\nYour first name please : ";
- cin.getline(fname,15,'$');//programmingisbest.blogspot.com
- cout<<"\nEnter your last name please : ";
- cin.getline(lname,15,'$'); //programmingisbest.blogspot.com
- //cout<<"\n\n YourName : "<<fname<<" "<<lname;
- int counter = 0;//programmingisbest.blogspot.com
- char ch='a';//programmingisbest.blogspot.com
- int flag = 0;//programmingisbest.blogspot.com
- int loop = 1;//programmingisbest.blogspot.com
- while(ch<='z')
- {//programmingisbest.blogspot.com
- if(flag ==0)
- {//programmingisbest.blogspot.com
- if(ch == fname[counter])
- {//programmingisbest.blogspot.com
- counter++;
- ch='a';
- }
- else
- {//programmingisbest.blogspot.com
- ch++;
- if(fname[counter] =='\0')
- {//programmingisbest.blogspot.com
- flag = 1;
- ch='a';
- }
- }
- }//programmingisbest.blogspot.com
- else
- {
- if(ch == lname[loop])
- {
- counter++;
- loop++;
- ch='a';
- }
- else
- {//programmingisbest.blogspot.com
- ch++;
- } //programmingisbest.blogspot.com
- } //programmingisbest.blogspot.com
- }//programmingisbest.blogspot.com
- cout<<"\nCounted characters in whole name are : "<<counter;
- _getch(); //programmingisbest.blogspot.com
- }//programmingisbest.blogspot.com