C++ :: Capitalize Every Other Word In A User Input String
Nov 14, 2014
I've been agonizing over this all day. The assignment is to capitalize every other word in a user input string.
My logic is as follows:
1. I have the program get each character until it encounters white space (using for loop)
2. Then it should capitalize each character after the white space until it encounters another white space (using while loop).
My problem though is when i try to create a condition for while loop i have to terminate is when white space is encountered, but the very first character to start the while loop is a white space..
I was told to define boolean values, but after trying a few boolean conditions I'm still stuck..
Code:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
[Code] .....
View 5 Replies
ADVERTISEMENT
Feb 26, 2013
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.
View 2 Replies
View Related
Jan 7, 2014
I have a difficulty with string methods for some reason. I tried solving a question from my book, which requires me to capitalize the first letter of every word in a string. I kept trying for maybe two hours yesterday, re-reading the string chapter to see if I'm forgetting a certain method or if something similar was discussed in the examples but I didn't find anything. I also googled it, and found a few answers, none of which I understood. They mostly had keywords or methods I wasn't familiar with. Anyway, here's where I am so far.
class Program {
static string UpperCase(string s) {
int place; string b, st1, st2,st3; char letter;
for (int i = 0; i <= s.Length - 1; i++) {
if (i == 0) {
[Code]....
The code compiles without any errors, but when I enter a string it capitalizes correctly for the first two words and then it starts capitalizing letters in the middle of the words.
View 14 Replies
View Related
Dec 4, 2014
I'm creating a program that takes user input in the form of a string and tests to see if it matches a word. Each correct word will increase their score by one. Here is a portion of the code that is not working.
...
else if(s == 32) {
if(!currentLetter.empty()) {
currentLetter.erase(currentLetter.length() - 2, currentLetter.length() - 1);
} if(currentLetter.compare(oWord) == 0) {
[Code] .....
To me, this looks like it should do a very simple task as intended-take a String, compare it to another, and reset the word if they match or output incorrect if not. But, I'm not sure if there is some quirk in C++ with Strings, because this code always outputs Incorrect. Please try again. and the score never increases. I also tested this by literally setting the strings equal in the code, which still resulted in it not doing what it's supposed to.
View 3 Replies
View Related
Mar 16, 2013
im trying to capitalize every other word. for examples input: hello output: HeLlO
View 5 Replies
View Related
Mar 1, 2015
So this is my homework: a user will enter a line of text, echo the input one word per line and capitalize each word(do not use toupper) and also needs word count and punctuation marks count. I know how to echo one word per line. How to capitalize each word without toupper? and how to do word count?
View 3 Replies
View Related
Oct 2, 2014
I'm working my way through some C exercises to get some practice and have hit a wall. I need to use a function to take a number, such as 1, and print out One.Here's what I've got so far:
Code:
#include <stdio.h>
int name(int n);
char numberOne[] = "One";
int main(void)
{
int n;
}
[code]...
However, when I run the code and enter "1" the only thing that gets printed to the screen is "(lldb)". I've tried changing it to doing it without variables and just printing "One" but that gave the exact same result.
View 6 Replies
View Related
Sep 22, 2013
I need to write a C program to make the user input some text,and the first letter of each word has to be uppercase.(have to use while loops)So for example lets say the user inputs:
i lOvE pRoGrAmMiNg
The output needs to be:
I Love Programming
Code:
#include <stdio.h>
int main()
{
int i = 0;
char c, lower_c;
printf("Enter text
");
[code]....
I have started this code by making the letters lowercase.I am not sure how proceed after this step, the step of making the first letter uppercase.
View 2 Replies
View Related
Dec 10, 2014
Write a program that inputs a string and then converts each 1st letter of a word in the string into capital case. An example run of the program is shown below:
Enter string: introduction to programming
Output string: Introduction To Programming
View 1 Replies
View Related
May 31, 2013
Write a function that accepts a pointer to a C-String as an argument and capitalizes the first character of each sentence in the string. For instance, if the string argument is "hello. my name is Joe. what is your name?" the function should manipulate the string so it contains "Hello. My name is Joe. What is your name?" Demonstrate the function in a program that asks the user to input a string and then passes it to the function. The modified string should be displayed on screen. Optional Exercise: Write an overloaded version of this function that accepts a string class object as its argument.
#include<iostream>
#include<cctype>
#include<cstdlib>
using namespace std;
void capitalize(char sentence[], int const SIZE);
[Code]...
Not even sure if I'm headed in the correct direction, but I'm getting the following errors:
E:CPT-233Sentence Capitalizer.cpp In function `void capitalize(char*, int)':
34 E:CPT-233Sentence Capitalizer.cpp call of overloaded `strstr(char&, const char[2])' is ambiguous
note E:CPT-233<internal>:0 candidates are: char* std::strstr(const char*, const char*) <near match>
note E:CPT-233<internal>:0 char* std::strstr(char*, const char*) <near match>
what I'm doing wrong?
View 2 Replies
View Related
Jun 25, 2014
Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.
I'm having trouble receiving that random word and I'm getting the definitions from the file.
Here's my code:
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
[Code] ....
This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet
View 3 Replies
View Related
Oct 24, 2013
I'm learning programming, and C++. I've got a question, but I couldn't solve my problem so far. I need to use arrays and only basic stuff to solve this:
Create a program that reads a word from the user and then print (cout) this word on contrary. It's simple, I know, but I can't do it,. I've tried some stuff but I don't get how I will get the proper values to do this. All I know is that I can use variable.lenght().
View 7 Replies
View Related
Jul 14, 2014
I have problem with string compare. I want to compare the string user input with a string in binary. And I don't know how to do it. Problem in function login();Here is the code: And you also can download file in attachment too..
Code:
#include<conio.h>#include<dos.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
char nsb=1;
char ch, password[20], passlogin[20], inputpass[20], checked[20];
FILE *fp;
}
[code]....
View 1 Replies
View Related
Feb 23, 2015
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;
[code].....
View 7 Replies
View Related
Jun 18, 2013
I have a problem that states: age is an int variable and name is a string.
What are the values of age and name after the following input statements execute.
cin << age;
getline(cin, name);
if the input is:
a. 23 Lance Grant
b. 23 Lance Grant
Ok I have been fooling around with this book all day. My instructer wants us to build the program instead of just saying
a = 23 Lance Grant
How to input B. I mean when I write the program I do not know how to ask for two lines for one input.
View 1 Replies
View Related
Feb 11, 2013
I need to write a program using at least one while loop to count and display the amount of vowels in a user input string. This is what I have so far.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int acounter(0); // Create counters for each vowel
[Code] ....
View 2 Replies
View Related
Nov 8, 2014
I'm trying to code the program that will store item data.And I'm having problems to receive user-input string to array.
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iomanip>
using namespace std;
[code].....
View 6 Replies
View Related
Oct 9, 2014
Is it possible to store information in a string without user input? If so, what code would I use for it?
View 2 Replies
View Related
Oct 25, 2013
I have been reading up on arrays and string array. I created a string string text[0] and it is defined by user input. I am trying to sort the input. I want Michael to read Macehil.
When I wasn't using an array and just a string I did this:
return sort(text.begin(), text.end()); a
And it worked fine. Do I need to change my string into a char? If so, would I static cast that?
View 9 Replies
View Related
Apr 22, 2014
I am writing a code in a class that will change the user input which is integer to a string. For example if the user enter 13347..the output should change to "one three three four seven" on the user screen.I'm not getting the right output.
Code below:
#include <iostream>
#include <string>
using namespace std;
string arr[]={"one","two","three","four","five","six","seven","eight","nine"};
class convertTo{
public:
int signed num;
int convet(){
cout<<"Enter a number to convert to string "; cin>>num;
[code]....
View 2 Replies
View Related
Aug 13, 2013
how to remove the vowels from the user input.?
View 4 Replies
View Related
Sep 21, 2014
This program will allow the user to input string then scans the file if it contains the same string given by the user. But i always get "MATCHED" even if i enter random string. I tried and tried to place the if statement in different positions but i dont get my expected output.
Code:
#include<stdio.h>#include<stdlib.h>
#include<time.h>
#include<string.h>
int main() {
int found;
[Code] ....
View 6 Replies
View Related
Mar 13, 2013
how to read characters from user and construct a sting and then extract part of it using substring?
View 2 Replies
View Related
Sep 30, 2013
How would you search in a vector array from a user input string?
ex: user input : "Hello"
output: search vector array and find the line that has the string "Hello" and output the array "Hello" is on?
View 1 Replies
View Related
Feb 5, 2013
I'm trying to write a short program that takes the input from a user and trims any leading/trailing white space, and then checks how many words are in the string. Problem is, I'm only allowed to use stdio.h and stdlib.h. How can I accomplish this? Also, how would I check if any of the characters which were entered aren't either a number, letter, or '-'?
View 3 Replies
View Related
Jan 28, 2015
Having problem with my code. i keep getting an error towards the bottom of the code. i need the user to enter a word. and with that word convert it to numbers. once i have convert it if it is bigger than 20 i have to add the two digits together and get print out the array that response to it.
example" ALEX
A=1
L=12
E=5
X=23
1+12+5+23= 41 //since its bigger than 20 you add 4 and 1 together so it will be 5. after that you print the 5th element of array
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
[Code]...
View 2 Replies
View Related