C++ :: How To Make Cin Accept Different Punctuation From Vector
Mar 7, 2013
My program is a dictionary vector with a cin at the end that will read your input and check if it's in the dictionary.
#include "std_lib_facilities_3.h"
#include <algorithm>
#include <string>
#include <iostream>
string translate_to_lower(string s){
transform(s.begi[/code]n(), s[/code].end(), s.begin(), (int (*)(int)) tolower);
[Code] ...
How do I make the program accept inputs such as "hello?", "hello!", and "hello,"?
View 1 Replies
ADVERTISEMENT
Jul 29, 2014
Now, I have an assignment in which I am to accept arguments from the command line and copy them into a cstring and display said cstring unmolested. Then I should store it into another cstring but ignore all punctuation, spaces and capital letters. Like this:
./a5 Marge lets Norah see Sharon's telegram
As is: Marge lets Norah see Sharon's telegram
---->: margeletsnorahseesharonstelegram
<----: margeletsnorahseesharonstelegram
Sequence entered is a palindrome
=======================================================
Finally I am to chaeck to see if it is a palindrome. Most of it works and if no spaces are entered nor punctuation it works. However, punctuation causes it to malfunction.
char *FormSeqProc (int argc, char *argv[], char seqAsIs[]) {
int len = 0,
n = 0;
for (int p = 1; p < argc; ++p) {
len += strlen(argv[p]);
[Code] ....
View 6 Replies
View Related
Dec 11, 2014
I have it searching through the entire string letter by letter, looking for spaces, punctuation, etc... yet it still is continuing on with the space.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdio.h>
#include <cctype>
#include <algorithm>
[Code] ....
Output:
if(str_word == " ")
//or
if(str_word == ' ')
It does nothing to change it. I am completely baffled.
View 4 Replies
View Related
Oct 13, 2014
Write a program that reads a string of characters including punctuation and writes what was read but with the punctuation removed.
This is how i did it:
string x("#punctuation!?=");
cout << x << endl;
for(unsigned i = 0; i < x.size(); ++i) {
if(ispunct(x[i]))
x[i] = ' ';
cout << x << endl;
I am just not sure if thats how they want you to do it because it doesn't remove the punctuations it just replaces them with a space.
View 3 Replies
View Related
Feb 8, 2014
I am trying to make a 5x3 2D-vector of integers, then set its i-capacity to be 5 and j-capacity to be 3, i.e:
vec2D[i][j] i = 1,2,3,4,5 j = 1,2,3
and then assign integer values to it.
#include <vector>
#include <iostream>
using namespace std;
int main () {
vector<vector<int> > vec2D;
[Code] ....
It compiles, but does not work properly:
Test.exe exited with code -1073741819
i-capacity before reserve: 0
i-capacity after reserve: 5
i = 0
j-capacity before reserve: 336043326
j-capacity after reserve: 336043326
i = 1
j-capacity before reserve: 4282929217
j-capacity after reserve: 4282929217
Press <RETURN> to close this window...
I am trying to convert a C code with dynamic 2D arrays, to a C++ code. I prefer to keep the vec2D[i][j] = ... way of assignment instead of using vec2D.push_back(...).
View 8 Replies
View Related
Jun 8, 2013
let say
char temp[8][8];
and you want to make vector of this char
vector<????> boardVec;
View 2 Replies
View Related
Oct 6, 2014
I have this piece of code in parts of my path finding algorithm
for( int head; head < q.size(); ++ head ){
walk& w = q[head];
// do manything with w
if( some_condition ) q.push_back( walk( w.x + 1, w.y, head ) );
}
However I notice that sometimes w is cannot be dereferenced. It can but it throws junk number at me. Perhaps the vector is changing it size and move the whole array to a different location. Is there anyway to make sure that w is always valid ?
I just want to use w because of shorter typing and cleaner look not because of performance. I also refrain from using macro.
View 8 Replies
View Related
Mar 9, 2014
I am supposed to make a scrabble game and randomize 10 of the letters.
Here's my code:
class Spinner
Spinner::Spinner(string things[], int numThings[], int n)
{
currentPosition = 0;
[Code].....
View 2 Replies
View Related
Mar 24, 2013
char *name[50]
How to accept 50 names using above definition...
View 3 Replies
View Related
Feb 14, 2013
For a program I am required to use a cin that accepts 4 variables. The first describes a function such as add(), remove(), print(), or quit(). The problem is that to use add() I need to input all 4 variables but for remove(), only 2 variable input is needed.
I want the input to be "add 9 James Bond"
or be "remove 341"
Here is my current code.
int command(string command, int Id, string first, string last){
while (command != "quit"){
cout << "customers> ";
cin >> command >> Id >> first >> last;
if (command == "add")
[Code] .....
View 1 Replies
View Related
Feb 7, 2015
I want to accept numbers from the user into an array and convert into corresponding alphabets. E.g 1 into A, 2 into B, and so on.
This is simple, but the problem is the user is supposed to enter the character # also which I want to display as it is in the output. How can I do this ? What type of array should be used - int or char?
View 5 Replies
View Related
Jun 17, 2014
Basically I do not want to use a menu, instead just accept either an float or a single character. Then send the data to the appropriate spot based on the user input. I have been unable to convert the char to a float, and even if I did the char would probably only accept the first digit, say user enters '15' it would only read the '1'. I've tried strings instead of char but then unable to use the isalpha function. Do I need a char[] and then iterate through to get the numeric data? Then how do i make '1' and '5' become 15. There is probably a solution. I've also tried to use a loop waiting for the correct data while(!(cin >> letter)) which works but how do I get out if the user enters number.
#include <iostream>
#include <cctype>
#include <string>
#include <cstdlib>
using namespace std;
[code].....
View 3 Replies
View Related
Sep 4, 2013
how can I create a program that will accept 2 two integers. the user will also choose among the different operations:
1 for addition
2 for subtraction
3 for multiplication
4 for division
View 4 Replies
View Related
Oct 28, 2013
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.
View 3 Replies
View Related
Feb 5, 2014
What I want to do with my program is I want my length, width,volume and price to accept number values only. This is what I have so far.
// This program calculates and displays the pool's volume
// the amount of water needed and the cost.
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
// the double type accepts numbers including fractions for the following inputs.
double length, width, depth, poolvolume, watervolume, price;
[Code] .....
View 1 Replies
View Related
Apr 20, 2013
I was trying to look up solution for this for quite a while already but found nothing. I am writing a simple console based turn based RPG game for my class project. I was trying to have a member function attack() in class of the player character, which affects the component called health of the class Enemy. both this classes are inherited from the base class Unit. I tried to pass the object of type enemy as an argument to the function attack, but the function call gives me Error: too many arguments in function call. Here's the code for classes:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
class Unit {
protected: int power, intellect;
[Code] ....
View 5 Replies
View Related
Jan 26, 2014
class Program {
//Accept two input parameter and returns two out value
public static void rect(int len, int width, out int area, out int perimeter) {
area = len * width;
perimeter = 2 * (len + width);
[Code] .....
why is the static keyword required in the method signature for the rect() method. It will not compile if it is absent. why?
the same is true for this example:
class Program {
static void printvalues(params int[] passedin) {
foreach (var printthis in passedin) {
Console.WriteLine(printthis);
[Code] ....
This code won't compile without the static keyword in the printvalues() method signature. why?
View 13 Replies
View Related
Jun 13, 2014
string answer;
cout<<"5.Newton's which law states that F=ma?";
cin>>answer;
if (answer == "newton's second law")
[Code].....
View 6 Replies
View Related
Feb 28, 2015
Create Binary Search Tree that will accept integers in this order: 35, 18, 48, 72, 60, 25.
It needs to prompt the user for input and then return either "True" or "False" if the number exists in the array.
#include <iostream>
#include <string>
#include <cstdlib>
[Code].....
View 2 Replies
View Related
Apr 30, 2014
I am creating a WinForm registration application and my program accepts user input information and stores it but I am struggling to use my login function. I believe there is an error in the area of cmd.Parameters.AddWithValue section, I dont think addwithvalue is correct ? I get a fatal crash has occurred when I click Login
string constring = "datasource=127.0.0.1;port=3306;username=root;password=welcome";
string Query = "SELECT * FROM 'userinfo'.'users' where 'username' = @userid and 'password' = @password)";
MySqlConnection conDatabase = new MySqlConnection(constring);
MySqlCommand cmd = new MySqlCommand(Query, conDatabase);
cmd.Parameters.AddWithValue("@userid", this.userid_txt.Text);
cmd.Parameters.AddWithValue("@passone", this.passone_txt.Text);
[code]....
Fixed the crash error, simple typo but now I am getting SQL Syntax errors which I originally believed I fixed.
View 1 Replies
View Related
Jun 18, 2014
i'm wondering if this will work
string user;
remove(user+".txt");
View 3 Replies
View Related
Aug 24, 2013
Can I create 1 variable that accept any type? And can I give it the NULL value too?
View 14 Replies
View Related
Dec 24, 2014
I've been experimenting a bit and can't find a decent way to make a brute forcing script that accepts a password from standard input, and goes through all possible combinations until it is matched. How to structure the code?
View 1 Replies
View Related
Nov 12, 2014
#include <iostream>
#include <iomanip>
using namespace std;
// Function Prototype
void sortArray(int array[], int size);
[Code] ....
This program was made to allow students to enter as many test scores as they want and the program will show them in ascending order and then will calculate the average of all test scores. It works wonderful until you enter a negative test score and then it throws the averaging process off. I can't seem to be able to make the program not accept the negative numbers.
View 1 Replies
View Related
Feb 28, 2013
#include<iostream>
using namespace std;
int main() {
int a[9],x,f=1;
cout<<"Please enter an integer [0-10 only] : ";
[Code] ....
View 3 Replies
View Related
Aug 10, 2014
So this is the activity (LOOPING) :
Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.
OUTPUT must be:
n = 5
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0
if n = 6
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0
6==5==4==3==2==1==0
View 2 Replies
View Related