C/C++ :: Input Validation With Strings And Int

Apr 15, 2014

I am having a problem with my "void Validation :: getId()" function its suppose to get the id number from the user but when I try and type a letter to see if it catches it, it goes into this continuous loop. Also with my "string Validation :: getName(string name)" function it suppose to catch the comma in the user input for their last name , first name but doesn't catch it and still returns the name back to main function.

#include "InputValidation.h"
#include <iostream>
using namespace std;
Validation :: Validation() {
name = " ";
id = 0;

[Code] ....

View 1 Replies


ADVERTISEMENT

C++ :: Input Validation For Date?

Jul 19, 2013

How do you do the input validation for date? I used:

char rec.date[SIZE];
cout<<"date"<<endl;
cin.getline(date,SIZE);

I want the user to write in this format (mm/dd/yy)

View 3 Replies View Related

C++ :: Input Validation In For Loop

Aug 14, 2014

// PROBLEM - Use INPUT VALIDATION so number entered is positive. I can't get it to work

#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, const char * argv[]) {
// SUM OF NUMBERS
// Enter a positive integer

[Code] ....

View 2 Replies View Related

C++ :: Cin Input Validation Returns Wrong

Jul 11, 2014

I have this function that is supposed to take a float as a parameter and then call the getLine() method to accept the users input. The function basically just checks to see if what the user input was of the same data type, if it is it returns the input value, if not then it keeps looping through taking new input until its correct. The problem is no matter what number you put in the output always returns as 140734799803512.

float InputValidation(){
float num;
string strInput;
while (true){
getline(cin, strInput);

[Code] ....

You also need to include <string> and <sstream>.

View 3 Replies View Related

C/C++ :: Float User Input Validation

Feb 4, 2014

How I could correctly validate user input when the user inputs a numeric value that will be float pay1, pay2, pay3, pay4. However, the if statement that I wrote crashes after I test the validation. I been told that scanf is dangerous, but strtol works best, but how to write a validation with strtol.

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define ARRAYSIZE 2
#define FORMAT "First Name Pago1 Pago2 Pago3 Pago4 Total Net"
#define FORMATHEADER "Last Name "

[Code] ....

View 3 Replies View Related

C :: Input Validation - User To Enter Six Doubles

Dec 20, 2014

I'm trying to validate my input. I require for the user to enter six doubles and if they don't then I want them to re-enter the information. Here is my code:

Code:
while (1>0) {
printf("Please enter arguments in the order: negative mass, positive mass, initial x-position, initial y-position, initial x-velocity, initial y-velocity:
");

if ( scanf("%lf %lf %lf %lf %lf %lf",&MassMinus,&MassPlus,&Pos[0][0],&Pos[0][1],&Vel[0][0],&Vel[0][1]) != 6) {
printf("Not all numbers were assigned!

[Code] .....

At the moment it just waits if you enter less than six numbers and if you enter any more than 6 it just ignores anything after the sixth number (so pretty much does nothing). Also if I entered 1 2 a b 3 4 instead of entering six numbers it would register that as 1 2 0 0 3 4 but I want it to make the user input the numbers again. I'm also aware that "while (1>0)" isn't good programming form but I'm not really sure what to use instead?

View 11 Replies View Related

Visual C++ :: Input Validation Error Using Arrays

Jul 18, 2013

I have not completed this program yet, but I have already run into a snag. For the Input Validation part, every time you enter a number regardless if it is positive it will still display the cout statement: "Please enter positive values". The program runs correctly where I currently am at, but it just keeps reading that statement even if a user enters a positive value. I have run the debugger, but it really is not showing me anything other than I notice it jumping to that statement after every value that is entered.

Here is my code, once again I have not finished this yet, but I would really like to get this fixed first before I continue. I will keep debugging in the meantime...

Code:
// A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 X 7 array, where each row represents a different monkey and each column represents a different day of the week. The program should first have the user input the data for each monkey. Then it should create a report that includes the following information:

// Average amount of food eaten per day by the whole family of monkeys.
// The least amount of food eaten during the week by any one monkey.
// The greatest amount of food eaten during the week by any one monkey.

// Input validation: Do not accept negative numbers for pounds of food eaten.

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

int main() {
double totalAverage = 0; // variable to store the total average, initalized to zero

[Code] ......

View 11 Replies View Related

C++ :: Input Validation For 5-digit PIN Number Read From Integer

Oct 22, 2014

The problem states that i need to accept any pin number between "00000" and "99999". I need to read the PIN the user enters as an integer. The problem is that if the PIN is read as an integer, the PIN "01111" will be "1111" which is invalid and the pin "00001" would be read as "1" which is also invalid. How would I go about fixing this problem for PIN numbers that start with a "0"? Again I cannot read the PIN as a char array or string.

View 2 Replies View Related

C++ :: Input Validation - Program Cannot Accept Negative Numbers

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

C/C++ :: User Input Validation - Finding GCD And LCM Of Multiple Numbers

Oct 23, 2014

I need validation on what the user inputs. Input should not be an alphabet, empty, and not negative number. This program is for finding the GCD and LCM of multiple numbers.

#include <stdio.h>
void bubble_sort(int numbers[], int len) {
int i, j;
int swapped;

[Code] .....

View 2 Replies View Related

C :: Validation Loop - Displays Error Message When Input Is Outside The Range

May 14, 2013

I am trying to get this simple validation loop to work so that it only displays the error message when the input is outside the range 1-3. yet it always seems to display the message.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int Menu ();
int ValidInt(int , int );

[Code] ....

View 5 Replies View Related

C++ :: Display Triangular Pattern - infinite Loops From Input Validation

Mar 1, 2014

I am writing a program to display a triangular pattern using nested loops and user input for the size of the base and character used to generate the image. 99% of the program runs fine. However I am having trouble with some of my input validation.

When given an integer value for the base I can verify if it is within a certain range (0-80). However, when the user inters a "char" instead of an "int" the program enters an infinite loop.

Here is the piece of code giving me trouble. (I wont bother you with the entire chunk of code, I have commented out everything else to narrow down the problem bit)

// Pattern Displays
// program that asks user for the size of the base of a triangle and then generates it in a character the user chooses

#include <iostream>
#include <istream>
#include <string>
#include <cstdlib>
using namespace std;
int main () {
char escape;

[Code] ....

View 2 Replies View Related

C++ :: Input Validation - Prevent User From Entering Characters Or Symbols Instead Of Numbers?

Jul 19, 2013

How do I prevent user from entering characters or symbols instead of numbers?
int num;
cout<<"Enter a number."<<endl;
cin>>num;

Also, how do I prevent user from entering a number instead of a character?
char c;
cout<<"Enter a character."<<endl;
cin>>c;

View 9 Replies View Related

C/C++ :: How To Input Strings Into 3D Array

Feb 19, 2014

I was very much confused with managing the 3d arrays. Other than initialising it is tough for me to input the data into the 3d array at runtime. I have tried the every possible method i know untill now but i can't successfully input and output the data.

I have written a code by declaring the 3d array of char s[5][2][20] in main and passing it's base address into another function, lets say input(char (*p)[2][20],int ,int ,int). I have passed the 3 dimensions in declaration 5,2,20 to the input function i have used these 3 values as the subscript for the pointer p and tried to input the data. But i wasn't successful.

How to input the strings into the 3d array.

My preferences were:

1.The change of subscript value should take place in loop(eg:for).
2.Which indexes should be used for inputing the data through pointer.
3.Use either "scanf" or "gets" function to inputs the data and print using "printf" or puts.

View 1 Replies View Related

C :: Program To Match Strings From Input To Files Using Dfa

Sep 2, 2013

'Write a program to match the user input string with the contents of text files and give the result as to which files contain the input string. This has to be done by using finite automaton.' (Any language can be used) So basically, the user will input a string (in the command line or a gui) and "we must pass the text files to the DFA" (I'm double quoting this because it's precisely what my professor told) and then display those files which contain the string. The string can be hard-coded, ie,the user will get the output file that contains a specific string. ex: 'hello'. The problem is, I have never done any program on DFA so I'm at a loss. how to write the program. Should I read the files first and then use some 'switch' or 'goto' conditions for the DFA? Below is a code I found on the internet for simulating a DFA accepting a specific string.

Code:

s: accept = false; cin >> char;
if char = "m" goto m;
if char = EOF goto end;
goto s;
m: accept = false; cin >> char;
if char = "m" goto m;
if char = "a" goto a;
if char = EOF goto end;
goto s;
}

[code]....

View 3 Replies View Related

C# :: How To Match Regex If Input Was Array Of Strings

May 19, 2014

In the MSDN, it gives an example using Regex.Matches method:

using System;
using System.Text.RegularExpressions;
public class Example {
public static void Main() {
string pattern = "a*";
string input = "abaabb";
foreach (Match m in Regex.Matches(input, pattern))
Console.WriteLine("'{0}' found at index {1}.",
m.Value, m.Index);

[code]......

I am wondering if string input was an array of strings instead, how would I use Regex.Matches?

What I was thinking about doing is having the input array set to ToString(), input.ToString(), but that doesn't seem to work.

View 9 Replies View Related

C++ :: Output Vowel From User Input - Error With Strings And Functions

Nov 25, 2014

The program is supposed to read in a string from the user and then output the number of each vowel that the string has. My first function is initializing the vectors, and the one that I'm having trouble with is the function used to read the string from the user and save it.

Here's my code:

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

// FUNCTION PROTOTYPES GO HERE:
void init_vectors(vector<char> & vowels, vector<int> & frequencies);
string read_text(const string & prompt);

[Code] ....

And I'm getting the error:

freq.cpp: In function ‘std::string read_text(const std::string&)’:
freq.cpp:74: error: no matching function for call to ‘getline(std::istream&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’

I'm not too sure if I can't use the function getline here or if there is something wrong with the function prototype itself but I'm pretty sure there isn't an error there as it was given to me.

View 4 Replies View Related

C++ :: Program To Check Validation Of Functions

Apr 12, 2013

I'm writing a program to check whether codes from a file are invalid, valid, inactive, or valid and active, but can't get it to work properly. The invalid codes are being found, but the other three are not. I think it may have something to do with my "active" function.

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

struct ActiveCodes {
string code;
bool flag;

[Code] ....

View 19 Replies View Related

C++ :: Selecting Design Pattern For Validation

Jan 21, 2015

I am looking into some design pattern which works for validation.

I thought about using strategy but not sure whether its correct or not

View 3 Replies View Related

C++ :: Email Validation Without Using Regular Expressions?

Dec 11, 2013

writing a program for "Validating the e-mail id without using regular expressions in c/c++"?

View 4 Replies View Related

C++ :: Bool Logic For Date Validation

Sep 17, 2013

My issue is regardless of which date I input its always defaulting to the values I have set in my constructor in my implementation file in the else statement. So the values always default to 3/15/2006 I think its something to do with the logic in my bool function but I may be incorrect.

header
//date.h header
#include <iostream>
#include <string>
using namespace std;

enum DateFormat {numeric, standard, alternative};
const int MIN_YEAR = 1900;
const int MAX_YEAR = 2015;

[Code] ....

View 4 Replies View Related

C++ :: Data Validation For Vowels And Consonants

May 12, 2014

I'm trying to make a function that verifies if the char entered is consonant, if not, prompts user to enter another char and when it meets the criteria, return the char. I was able to do this using switch statements (which works, and i'll paste it below) but I wanted to know if there was an easier, perhaps more elegant solution for accomplishing this goal.

char isCons () // data validation for consonants{
char userCons;
bool notCons = false;
cout << "Please enter a consonant: ";
cin >> userCons;

[Code] .....

View 1 Replies View Related

C# :: Proper Validation Of Text Boxes?

Dec 1, 2014

So I am writing a multiform multiclass project for a class and I initially set out to create a validate class to check all of my text boxes. However after writing a few simple boolean functions to check if the box was empty or not, or if it was indeed an integer, decimal ect. I realized I was going to have to call these functions for every text box and also have all of my decision making based on the returned boolean variable still in the code portion of my form. I was wondering how do most people do it, should I write a class that validates the entire form at once(one form has 7 text boxes, one has 9). I suppose I am asking what would the industry standard be, how would a professional do it? While my simple functions would work, and while I could write one large function that validates them all at once both paths leave something to be desired in terms of re-usability for the entire form validation, and compact/cleanliness of code for the simple functions.

My validate class currently stands like this:

class Validate {
bool isValid = true;
int trash;
bool valid_string(string input) //parameter is textbox.text property {
if (input == string.Empty)

[Code] ......

View 7 Replies View Related

C++ :: How To Create Type Validation Function

May 21, 2014

So I am writing an assignment to Detect prime numbers and it works by Asking for how many values you are going to enter, and then saying "Enter value 1: "

Then you would input and it would calculate via for loop, and that part is working. However to make my program more foolproof, I devised a way for the user to be unable to "Break" the program by inputting characters or float values. Here is the code for that:

while(!(cin >> num)){ //num is some type (char, float, int etc.)
cout << "That is not at valid input, please try again" << endl; //"Error Message"
cin.clear();
cin.ignore(10000, '
'); //Clear and reset cin
cout << "Enter value " << n << ": "; //Re-Prompt User for input
//n is whatever value the for loop is on
}

and this code works fine, I was just curious about how i would turn it into a function. Preferably wiht the name: ValidateInput(Param1, Param2);

The Parameters of the function preferably would be the variable youre inputting and the message you want to prompt. So somehow i wish to have it so for the above example it would look like:

ValidateInput(num, "Enter Value " << n << ": ");

But I don't know exactly how to label either parameter part because I want it to work for chars, ints, floats etc. And I don't know what I want it to return if anything either.

View 1 Replies View Related

C# :: Trying To Create Custom Validation Attribute

May 8, 2014

I am trying to create a custom ValidationAttribute in my c# .net code. I have done a lot of searching and have code that should be working but the IsValid method is not firing as far as I can tell.

Model code:

[Required(AllowEmptyStrings = false, ErrorMessage = "required")]
//[Range(2014, 2100, ErrorMessage="Please enter a valid year.")]
//[RegularExpression(@"^d{4}$", ErrorMessage = "Please enter a valid year.")]
[ValidYear(ErrorMessage="Please enter one >= 2014")]
[Display(Name = "Exp. Year")]
public string expYear { get; set; }

And this is the class in that same model:

public class ValidYearAttribute : ValidationAttribute {
protected override ValidationResult IsValid(object value, ValidationContext validationContext){
return new ValidationResult("Something went wrong");
}
}

Why the IsValid is not firing.

View 3 Replies View Related

C/C++ :: How To Give Validation For Character String

Aug 26, 2013

If i have character string 'char name[30]' how to give validation for the name entered by user?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved