Count the characters typed by user

for the program to count the characters i typed

Page 1 of 1

5 Replies - 3341 Views - Last Post: 09 December 2008 - 10:24 AM Rate Topic: -----

#1 hahagotu20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-December 08

Count the characters typed by user

Posted 08 December 2008 - 02:08 PM

trying to make the program count the the number of characters i typed 


#include<iostream>
using namespace std;

int main()
{
	
	
	
char character;
int i=0;


cout<<"enter the character "<<endl;

cin>>character;

for(i=0; i<=0; i++)

cout<<"the no. of characters you have entered are "<<i<<endl;

using dev c++



This post has been edited by Jayman: 08 December 2008 - 02:28 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Count the characters typed by user

#2 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Count the characters typed by user

Posted 08 December 2008 - 02:22 PM

You could use a string, and just output string.length() at the end, like so:
#include <iostream> // input/output stream
using namespace std; // the standard namespace,
// for stuff like cout and cin

int main() {
    string str; // the string (the user will input this
    cout << "Enter a string~!" << endl; // print a prompt and a new line
    cin >> str; // console input: get our string
    cout << str.length(); // the length of the string
    cin.get(); // pause, wait for the user to press enter before exiting
    return EXIT_SUCCESS; // success! w00t~!
}

Hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Count the characters typed by user

Posted 08 December 2008 - 02:28 PM

Modified title to be more descriptive of the problem.
Was This Post Helpful? 0
  • +
  • -

#4 hahagotu20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-December 08

Re: Count the characters typed by user

Posted 08 December 2008 - 02:36 PM

thanks that worked
Was This Post Helpful? 0
  • +
  • -

#5 GIJewishPenguin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 19-November 08

Re: Count the characters typed by user

Posted 08 December 2008 - 02:40 PM

The way i did it was:

#include <cctype> 
#include <iostream>
using namespace std;

int main()
{
char TextInput;
int Count = 0; // Initiates count.

 cout << "Enter Text." << endl; //prompts user to enter text.
 do
	{
	 TextInput = tolower(getchar()); // gets character then coverts to lowercase.
	  if( TextInput >= 'a' && TextInput <= 'z') // so it just checks for a-z if u want all
																 // characters including puctuation just remove.
		 Count++;
	 } while (TextInput != EOF); // will count the all letters can switch to '.' if u want it
											 // to stop counting at the period

cout << "You entered " << Count << " letters." << endl;

system("Pause"); //pauses Execute window.
return 0;
}




this will just keep adding until you hit enter.
Was This Post Helpful? 0
  • +
  • -

#6 hahagotu20  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-December 08

Re: Count the characters typed by user

Posted 09 December 2008 - 10:24 AM

View PostGIJewishPenguin, on 8 Dec, 2008 - 01:40 PM, said:

The way i did it was:

#include <cctype> 
#include <iostream>
using namespace std;

int main()
{
char TextInput;
int Count = 0; // Initiates count.

 cout << "Enter Text." << endl; //prompts user to enter text.
 do
	{
	 TextInput = tolower(getchar()); // gets character then coverts to lowercase.
	  if( TextInput >= 'a' && TextInput <= 'z') // so it just checks for a-z if u want all
																 // characters including puctuation just remove.
		 Count++;
	 } while (TextInput != EOF); // will count the all letters can switch to '.' if u want it
											 // to stop counting at the period

cout << "You entered " << Count << " letters." << endl;

system("Pause"); //pauses Execute window.
return 0;
}




this will just keep adding until you hit enter.



thanks guys for your HELP :) worked fined both suggestions
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1