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


ADVERTISEMENT

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/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++ :: 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++ :: No Input - Forcing User To Press Enter Twice

Aug 25, 2013

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?

View 2 Replies View Related

C++ :: Program Which Allows A User To Enter Input For A Time Interval

Apr 23, 2014

how can i make a program which allows a user to enter an input for a time interval for example i ask a question and sets the input to be entered within 10 seconds...

View 4 Replies View Related

C++ :: Accept Input Till User Hits Enter With No Text Typed

Feb 27, 2012

It seems to be going null. I can't get a null value, I want it to accept input till the user hits enter with no text typed. I've tried checking to see if the input is NULL, "", and " " all to no avail.

Code:
#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstring>
using namespace std;
int main() {
string info = "";

[Code] ....

View 7 Replies View Related

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/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 View Related

C/C++ :: Date Validation Accepted By User In Variable

Apr 12, 2012

Some example to validate date accepted by user in variable as follows:

int day;
int month;
int year;

It must validate entered details are correct or not ans

It must check that date is more than System date or not

View 6 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

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# :: Access To Other Form Once User And Password Validation Granted Subform

Aug 24, 2014

What I want is just to make a validation of the users and passwords already set within my array and go to the other form. By the way this form I already made it my start up form on program.cs with the same command I am trying to back to MainForm.

void Button1Click(object sender, EventArgs e) {
string error = "denied";
string[,] usrpass = {{"User1", "pass1"}, {"User2", "pass2"}, {"User3", "pass3"}, {"User4", "pass4"},
{"User5", "pass5"}};

[Code] .....

View 6 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 :: 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 :: Program That Will Allow A User To Enter Their Name

Jul 2, 2013

I am trying to make a program that will allow a user to enter their name, from this point, three options should be present for the user to choose, then from that point, two more options should be present. I have if else statements in a switch case and I get the "undeclared" error for the a in the first " if(specificage == a) ".

NOTE: I use Code::Blocks.

Here is the code:

Code:
#include <stdio.h>
#include <string.h>
int main(){
char name[50];
char ageclass[50];
char specificage[50];

[Code] ....

View 3 Replies View Related

C :: Flushing Input And Why Do Have To Hit Enter Key Twice

Mar 6, 2015

I wrote a program that reads user input string using fgets() function. After this, program will ask if the user wants to save the string to file or does the user want to change the string or quit without saving. If user wants to change the string this must be made possible by asking for the string again. After this, menu will be printed again printing the choices available.

I had to flush stdin before getting changing input! However, problem is "Why do I have to hit return key 2 times, when I choose 2 and input string again." (I use code block 13.12 with windows 8.1 laptop) */

Code:
#include <stdio.h>
#include <string.h>
#define MAX 50

[Code]....

View 9 Replies View Related

C++ :: How To Restrict User To Enter Four Digit Number Only

Aug 22, 2014

I am trying to write up something to have a user to enter a four digit number. Only four digits, Ex: 0001, 0116, or 9999. There is no getting around the selection 0001 or 0002. I understand if not done correctly, the first three 0's will be ignored.

I've been just playing around with what I have below but I just don't remember how to do it nor can I find a good example online to figure it out. I know it is not correct just typing to try to remember. I am aware that it is gibberish right now, this is just me brainstorming.

int number;
cout<<("Please enter the four digit number(Ex: 0001):
");
cin>> setw(2) >> number;
cout<<)"Please enter four digit date. Two digits for month and two digits for year:
");
cin>> date;
if (number< || number > 30)
cout << "Invalid choice. Try again." << endl;
cin.clear();

View 2 Replies View Related

C :: User To Enter 4 Integers Which Get Stored In Array

Mar 3, 2014

For my code, I want the user to enter 4 integers, which get stored in an array. Here are the lines I wrote relevant to this part:

Code:
printf("Enter 4 integers:
");
scanf("%d %d %d %d," &a, &b, &c, &d);
z[4] = { a, b, c, d};

Would this be correct?

View 5 Replies View Related

C++ :: Prompt A User To Enter M For Male Or F For Female

Dec 24, 2014

I am simply trying to prompt a user to enter M for Male or F for Female. However, when I test run the program (what I've got so far below), any letter inputted is accepted and continues the program..?

#include <iostream>
using namespace std;
int main() {
char gender;
int maleBodyWeight;

[Code] .....

View 2 Replies View Related

C++ :: Program That Will Ask User To Enter Area Of Square?

Feb 11, 2013

B. Circle in a Square Write a C++ program that will ask the user to enter the area of a square. Then the program will display the biggest area of a circle that will fit in a given square. Using math.h library is not allowed.

View 1 Replies View Related

C++ :: Program That Asks User To Enter Even Number Only

Mar 23, 2014

Write a C++ program that asks the user to enter an even number only. If the user enters an odd number the program should use input validation to ask the user to enter another number.

- The user can enter as many numbers as he wants

- The program should also keep a count of how many numbers entered and display how many odd and even numbers entered.

View 1 Replies View Related

C++ :: User To Enter Size Of Dynamic Array

Apr 22, 2013

I'm doing an exercise which involves for the user to enter the size of the dynamic array and then enter the numbers, but then it needs to create another dynamic array with the same numbers expect if the number repeats it only has one of it. I've done the first part of the exercise but I'm having trouble with creating the new array.

View 10 Replies View Related







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