C :: Counts Keystrokes / Alphabetical Characters And Vowels - Press Enter To Exit A Loop?
Oct 28, 2014
So I have been assigned a program that counts keystrokes, alphabetical characters, and vowels. I have the program working as desired but I just can't figure out how to make it end upon ONLY the "return" key being pressed.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ( void ) {
So I need to make a program that counts the number of words, lines, and vowels in a program. Punctuation and white spaces are not counted in any of the counts. I have this so far and the words, and lines work and are correct but I can't seem to get the vowel count to work.
When the user gives no input, they have to press enter twice before "Done." is printed.
cout << "What do you want the name of your page to be? "; std::getline(cin, pageTitle); if (cin.get() == ' ') pageTitle = "Welcome to Website."; cout << "Done. ";
Is there a way to print "Done." after pressing enter once?
Code: #include<iostream.h> #include<conio.h> #include<string.h> void main() { clrscr(); int i=0,flag=1; cout<<"Enter the password.";
[Code] ....
When I input the password, the Backspace and the Enter keys are not working as they should. Also, I want to know if I can press enter only once to input the password, not twice.
My program closes after the out even though i've used cin.get():
I want the program to stay open at least until you press enter, even after the whole output.
Code: #include <iostream>#include <string> int main() { std::cout << "Please enter your name"; std::string name; std::cin>> name; // build the message that we intend to write
I'm trying to create a program that counts the amount of alphabetical characters, numbers, blanks and total amount of characters in a string a user gets to enter. The user also quits the program manually by pressing CTRL + D (in linux terminal).
These are the results I get from the code so far by typing in "hello cplusplus 123 c++" CTRL + D.
The string had: Alphabetical characters...: 0 Numbers...................: 0 Blanks....................: 3 Total amount of characters: 20
So I can't seem to find a way to count the amount of alphabetical characters and numeric characters.
Here's my code:
#include <iostream> #include <string> #include <iomanip> #include <cctype> #include <sstream> using namespace std; int main() { string tecken;
[Code] ....
The reason why I declared cctype is that I think I should use the isalpha, isdigit and isblank functions but how I am supposed to do that.
Enter as many numbers as you want as long as the user doesn't type 'e' to exit.
Problem: When I enter a number, it works fine, but if I enter e then it'll go in an infinite loop since the letter is being stored in an int variable. How can I (when I press 'e') make it convert to a char to make it end the program?
#include <iostream> using namespace std; int main() { int num; cout << "Enter a number or press e to exit:";
[Code] ....
Our class has just started c++ and we have not learned arrays and classes yet, so I'm guessing there is a way to do this without it? Or no?
My question is how create a function to remove all vowels defined as characters('a' 'e', 'i', 'o', and 'u') from the array provided to it.
An example of how the function should work:
input: Hello world, how are you? output: Hll wrld, hw r y?
Code: int removeVowels(char arr[]) { int i; //move through each element of the array for(i = j; arr[i] != '/0'; i++) { //if the last character was a vowel replace with the current //character
for starters i hope this question wasn't posted yet.i want to write a small program that askes the user what he wants to do , and then executes the comand in system . But for some reason it doesn't quit on the key word this is the code:
Code:
#include <stdio.h> /*a simple interaction programme that schow the system options*/ #define systemt "x1b[32m" /*changes the color to green for system output*/ #define user "x1b[0m" /*changes the color to white for user input*/ int main() {
[Code]...
Is there something wrong white the code or does the system bock me from reusing the choise string. i'll inculde the original c file as well
The thing is, when I don't create a prototype of count and straightaway define it before void main() my program runs, but it gives error in this program that "extra parameter in call to count()" But what to do then?
i just want to break the loop when user hit ENTER.But after that programm is stil working, i don't know why, becouse i have a code just like in book, i spend a lot of time with it.
int getinfo(student pa[], int n){ cout << "START" << endl; int i = 0; for(i; i < n; i++) { cout << "Studetn name"; char name[SLEN];
I wondering how to stop a infinite loop. The program clears a file then opens it and refreshes it over and over(the file is going to be modified by another program). I want it to start from the beginning anytime i press enter or escape, it doesn't really matter as long as you can restart it.
How to fix this when i run the program and enter my name then output my name in vertical position using the for loop and press enter the program do not stop
I am unable to find why my code is going into infinite loop as below. This works perfectly fine if I keep entering just the integer values but if I enter a float number it ends up in an infinite loop
int main() { int x; while(1){ cin>>x; cout <<x; } return 0; }
Is it possible in C to instantly react to keystrokes made in console?For example, consider the following code:
Code:
#include<stdio.h> int main(int argc, char *argv[]) { char ch; printf("Enter a sentence... ");
[code]....
The evaluation of the if statement inside the loop will not occur until the Enter key is pressed on keyboard.To my best understanding, It just pushes the keystrokes to some buffer, and when the '' is introduced, it evalutes the characters one by one.Is there an elegant way to instantly react to keystrokes in C?