C :: Program That Counts Letters Of 3 Lines Of Input From User
May 26, 2013
So I am writing a program that counts the letters of 3 lines of input from the user. I am using a 3 x 80 character array as the "notepad". Upper and lower case characters are incremented on the same counter array.
Code:
/*Letters in a string*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void countAlphabet(char *);
/*Character counting array*/
int alphabet[26] = {0};
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.
I am trying to write a program to get user's input but only accepts alphabetic characters, nothing else and I want it to ask the user to enter a valid word until they have finally entered a valid one. I have the following code for it but it does not work properly.
void CheckBound (char word1[], int SIZE1) { int i; int w1[SIZE4]= {0}; int found; for (i=0;i<strlen(word1);i++) {
#include <iostream> #include <limits> int getInt() { int x = 0; while(!(cin >> x))
[Code] ....
But this function prompts the user to only input integer values. I was thinking if I could maybe try tweaking with this one so that the user could only enter letters..no luck though. So how can I have the user input letters only?
How do I error check if the user is inputting letters and not numbers? For example, if the user inputs "Lab.txt" I need to display an error message. If they input "Lab2part2.txt" then this is correct and what I want.
I've found a lot of information online on how to error check for numbers or a single letter (EX: 1,2,3, etc. or 'A' 'B' 'C') but nothing for actual WORDS or maybe I should refer to it as a string of characters?
Is there any way to do this? Because my program requires I ask the user to input the name of the file. But the way my code is currently set up is even when the user inputs the wrong file name it still opens the file. I want to prevent this from happening so my thought was to error check user input.
/*Program to determine company's weekly payroll*/
#include <iostream> #include <string> #include <fstream> using namespace std; void OpenTheFile() { ifstream inputFile; string filename; char letter; int number;
I am trying to build a c++ that reads user input and arrange letters in ascending order.
for example, if the user input: Hello my name is Moe! the output will be: !aeeehillmmmnoos (ascending order)
my problem is that when i input hello my name is moe the output will be ehllo (not completing other letters) also when i change class size to 50, it outputs unknown weird letters.
This is my code:
#define CLASS_SIZE 10 #include <stdio.h> #include <iostream> void bubbleSortAWriteToB(const char a[], char b[]); using namespace std; int main(void){ int i;
After the data is in the array, prompt the user to modify the array by inputting a species name and a count. If the species is not in the array, print a message indicating this and add the species to the end of the array. If the species is in the array, change the count in the array to the new count. Allow the user to input any number of changes.
This is what I have so far:
//Description of program:Manages a list of bird species and counts stored in an array of structs.
This is a command line lotto program. My first problem is trying to increment letters per line of the array. So for example, if the user types: ./mega_million 10
The output would be something like:
Mega Million ________________Mega A 17 30 32 33 38 30 B 14 21 23 45 52 16 C 03 08 17 42 44 30 D 01 11 27 35 45 29 E 07 12 16 32 46 06 F 17 39 50 52 53 44 G 13 32 49 52 53 39 H 16 41 53 54 55 11 I 14 45 46 53 54 28 J 36 37 42 53 55 39
#include <stdio.h> main() { int c, n1; n1 = 0; while ((c = getchar()) != EOF) if (c == '') ++n1; printf("%d", n1); }
I have a more complicated program I'm wishing to have display the output, however, to save some time I'm using an example of a shorter version. count the lines in input and display the output in terminal when ./program is executed after compilation. To count and compute lines, words and within arrays.
int main() { string filename = "Question 1.cpp"; // File name goes in here
[Code] ....
Now I am not sure if im suppose to get a msg saying : The file "Question 1.cpp" has 0 words.
im wondering is the question that im being asked, asking me to input a string of words and then the compiler when it builds and runs the program counts the word spaces.?
I built a program that accepts two input from the user, using a array inside a loop, it is pass to a function inside a class which will display the two number, the problem is when the user is inputting a number and it is 1 the program continuously as the user to input a number, and when 2 is entered the program ask another number and end, but for example you entered 2 and 3. . . it will then outpu 2 and 4 (so 3 + 1 ) and always the last number is plus one. here is the code.
main.cpp #include <iostream> #include "newclass.h" using namespace std;
So we have a weekend assignment that is "Write a c++ program that will allow a user to input their first name into a string, and use the switch/case statement to produce the following output. Your Program should prompt the use rwith the numbers and the options for each (school, classification, and mood) allowing them to make a choice"
My issue is with the output. The output at the end is the number that they input and not the name of the case they chose, so if they chose option 1 for school it does not print out "BRCC" at the end for the output it prints a 1.
#include <iostream> #include <string> using namespace std; int main(void) { string name; cout << "Please enter your name: "; cin >> name;
I need a program to run that will accept an input for user id. It will take the customer input and capitalize the letters, and return invalid id with the user inputted values. Then if it's valid it will add a counter counting the number of letters and numbers. It will keep track until the user puts in !. It seems when I try to pass values from the array to my toUpper function to capitalize it it doesn't seem to work right.
I am so close to finishing this program of games, but I'm running into some issues while debugging it.
I've attached the google drive folder since there are several files (ignore the ones with [conflict], etc)...
First, I have the main menu using a switch to select the game. The default was set to exit. If initially when immediately opening the program you put in for say, a letter, it would exit like its supposed to. But if you went and played any of the games ], went back to the main screen, and entered a letter then, it would crash. I've put in a testing line to make sure that you enter a number, and not anything else.
Now however, if you play a game and then want to go back to the main menu, it will simply skip over waiting for your response and close the program. The same thing happens in the slot machine, I want to have it spin the slot machine by pressing enter, but it simply skips over the input, and I'm not sure why.
I'm trying to write a program that capitalizes every other word of a user output. (ex: if input is "i love you", the output is "i LoVe YoU").
I am using a for loop (although an if loop might be easier?) and I'm assuming that it is possible to write this program using a for loop (although I may be wrong--maybe only if loops can write this program). I have everything down EXCEPT the last step where I have to print the entire sequence. What i have so far is:
Code: #include <cs50.h> #include <stdio.h> #include <string.h> { // get user input printf("Type a sentence: "); string s = GetString();
[Code] .....
The code above basically only prints out the capital letter (ex: input is "hello", output is "EL"). I don't know how to print out the entire sequence.
Thread 1 does some background work, and thread2 is waiting for the user's input. If I join thread1 then the app can never exit. If I neither join nor detach thread1 then I get "terminate called without an active exception Aborted" which is not a good thing to have. If I do detach on thread1 does thread1 ever terminate? If not, how to terminate it? Also, how do I check if it's terminated or not?
I need to create a program that will prompt the user for an input, then it will save their input to a file and then it will prompt the user to input "Open" and then the file containing their first input, will open up and show their input.
It's a tic-tac-toe program. I haven't finished doing everything I need to for the project, I'm just trying to get certain parts working as I go.
Anyway, my problem: The program will print the board and ask the first player which square they want to mark. Then it will print the updated board, print the question for the second player to input their square choice but not actually stop to let the user enter anything. Instead it prints the board again and then prints the question for player one again -- this time stopping to let them type in their choice.
Here's my code:
#include <stdio.h> // Function prototypes void printBoard(char board[3][3]); int main() { int quit = 0; // Loop so game continues until player quits
[Code] .....
And it looks like this when I run it, as an example:
I have an a problem I need to make lottery random generation program what asks from user how many lines to gerenate random numbers. But i am now stuck.
Console.WriteLine(" choose how many numbers "); int i = int.Parse(Console.ReadLine()); Random randomizer = new Random(); for(int j = 0; j < 7; j++) { i = randomizer.Next(1, 39); } Console.WriteLine("Your random numbers are{0}", i); Console.ReadLine();
#include <iostream> #include <string> #include <limits> //for std: numeric limits #include <algorithm> //Function to get an integer from the user that is greater than or equal to zero.
int getPositiveIntFromUser(const std::string& prompt) { int retVal = -1;
[Code] ....
The first part works, but it doesn't calculate the GCD or LCM at all, it just crashes!
Thread1 does some background work, and thread2 is waiting for the user's input.
If I join thread1 then the app can never exit. If I neither join nor detach thread1 then I get "terminate called without an active exception Aborted" which is not a good thing to have.
If I do detach on thread1 does thread1 ever terminate? If not, how to terminate it? Also, how do I check if it's terminated or not? -- I realize it's platform specific, I am on Linux.