C :: Comparing Between Date Variables - Validating Inputs
Oct 28, 2013
i have a code which compares between these two variables. date1 and date2. The program runs when the user input two correct dates eg: 20/10/2003 20/14/2004 then it will read and display values in between the date. That means if the user enters other characters like alphabets or other weird characters the program will prompt an error and not run.
Only with the correct input(int) then it can run. how can i implement this in that case? probably in real expressions or switch case? This is my code:
/*
* date_compare compares two dates, returning <0, 0, >0 if
* date1<date2, date1==date2, date1>date2, respectively
*/
int date_compare(Date *date1, Date *date2) {
if(date1->year < date2->year) {
//printf("Year is smaller");
[Code] ....
View 10 Replies
ADVERTISEMENT
Aug 31, 2014
I had problem in comparing 2 char vairable in check function
if(room_no==r)
variable r take input from user and compare to room_no read from file.
#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<dos.h>
#include<string>
#include<stdlib.h>
[Code] .....
View 2 Replies
View Related
Mar 5, 2013
1. In main() in the while loop entering 'q' does not exit.
2. in the isbnValidation function. The size check for minimum length words will work, but the check for "Invalid ISBN character" doesn't.
3. Every ISBN entered returns as valid. The formula is supposed to multiply the first digit by 10, next by 9 etc (skipping all the dashes) and add up to a weighted total which if valid will divide evenly by 11.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ISBNMIN 10
#define ISBNMAX 14
[Code].....
View 4 Replies
View Related
Oct 7, 2014
Validation opening/closing brackets.
I had the entire validation working until my professor said that my Pop function had to be a "void" not a "Char". Which destroyed my previous validation and now how to validate this.
I will only be posting the validating function.
All the characters are being thrown in a Stack. So I am using Pop/Top/Push/isEmpty/isFull. That will be shown in my validating code.
Correct Validations:
1. {}()[]
2. [()]
3. {([])}
Incorrect Validations:
1.[)
2.[(]]
3.{])
My main issue is that it validates "[)" correct.
I am pretty positive I must have over complicated my validation.
View 7 Replies
View Related
May 20, 2013
I am working on a program where the person enters their name and their gross pay. I had to validate that the gross was a number and contained no letters.
I also have to validate the persons name to see if it contains any numbers. The book I am using has an example with only an if statement that says if it is correct or incorrect. I was trying to use <cctype> and toalpha
I just was wondering if there was a way to put it into a while loop or how i would have it ask the user to input their name again. When i tried it just blew up.
Also in the book they use const int SIZE= 8, but I don't want to put a size on the name if I don't have to.
View 4 Replies
View Related
Oct 11, 2012
i'm making a program that, given a person's birthdate or any other date, will display the day of the week of the person was born.
There is this part where it says "use a switch statement to make this calculation, If desired month is 12, add the number of days for November, if desired month is 11 add the number of days for october....
So it's suppose to start with "case 12 :...
I can't figure out what to write for the statement....
View 6 Replies
View Related
Apr 29, 2012
Question simple like that: Let user enter some words from keyboard, one word per line until a '.' (period) entered then print out result, for example:
Code:
Enter a word: word1
Enter a word: word2
Enter a word: .
You have entered 2 word(s):
word1
word2
Problem is I don't know how to declare the array of character at the beginning since I don't know neither how many word user may enter nor how many letter of each word. So I go ahead and declared like this: char word[20][50] but I know it is not best way.
Code:
int main () {
char word[20][50]; //array has maximum 20 words, each word maximum 50 character
int i=0, number_of_word;
do {
printf ("Enter a word: ");
[Code] ....
View 3 Replies
View Related
Mar 28, 2014
I have two date/time structures which I'm populating, but when I populate the second one it sets the same values in the first. This is what I've got so far
tm *FirstDate = gmtime(&now);
tm *SecondDate = gmtime(&now);
cout <<"Enter your first date in the format dd/mm/yyyy" << endl <<">";
getline (cin,tempstring);
[Code] .....
View 2 Replies
View Related
Nov 29, 2013
Code:
#include <stdio.h>
int main(){
int A, B;
char decision;
printf("Do you have an integer to input? [Y/N]: ");
scanf("%c",&decision);
if(decision=='Y' || decision=='y'){
[Code]....
After entering a single integer, it doesn't scan again for another integer. What's wrong?
I'm using a mac btw, if that makes a difference with Ubuntu/Linux.
View 8 Replies
View Related
Dec 7, 2014
I have learnt recently how to use fgetc, fputc, fputs, fgets but still I am not able to figure out how to read values from a file like for example:
12 14 1928 32993932
17 98
166 109 201
These are separate integers & i want to read them and then manipulate these individual integers like going for 2*I1, 4*I2 and so on where I1 and I2 are 12 & 14.
View 2 Replies
View Related
Apr 9, 2014
I want to have calculations take place inside a switch statement that calls the appropriate function. The menu portion of the program works well, but I can't figure out how to let the user actually input 2 different numbers to the functions. My questions are:
1. If I use scanf to assign values to the variables, what determines end of input to each variable? (ie.. scanf("%d%d", &a, &b) what is the end of a, what is the end of b?)
2. Should I assign the variables to user input inside the switch, or try to do it in the functions below?
3. Is there something I haven't thought to ask that will screw me over? I'm really new to this.
Code:
#include<stdio.h>
int add(int b, int a);
int mult(int b, int a);
main() {
[Code] ....
This really was a test of multilayer menu, but I want to add functionality if I can.
Changed a variable before posting and didn't change all the conditions testing it.
View 3 Replies
View Related
Sep 27, 2013
On my program I use a counter to count to 10, then i ask for a string, in this case "yes" or "no", during the count, i want to keep the user from putting inputs in, due to the fact that if they put both "yes" and "no" before the program reads the string.
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
}
[code]....
View 3 Replies
View Related
Mar 2, 2014
it skips the input phase,, instead of inputting the last name it goes directly to the firstname then middle initail and street name are working fine but it skips the street name then goes to city and so on....
Code:
char l[50], f[50], m;char strtname[50], cty[50], cntry[50];
int strtnum, zp, i;
system("cls");
printf("Enter Last name:");
gets(l);
printf("
Enter First name:");
}
[code]....
View 3 Replies
View Related
Jul 23, 2014
I have a project that requires I take user input from menu options and put it into an array which I will average out. I can set the menu up I think, but I cannot understand how to put what the user inputs into an array. Granted I just took the lecture on arrays today. Also we can only use functions to do the work.
View 9 Replies
View Related
Nov 23, 2014
I don't know how many numbers will be the input only that its going to be up to 10000. EOF should be active. I tried it like this:
Code:
int i = 0;
int del[10000]
while (scanf("%d",del[i])!=EOF)
{
i++;
}
But it seems the value of i doesn't increment, could you provide some tips on how to scanf the inputs into an array if I don't know how many numbers will I have?
View 7 Replies
View Related
Oct 26, 2013
Any chances for a c program to check for browser inputs?
View 1 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 10, 2013
I am new to C++ and I want to learn how to set color a particular color for the users input and output. For example, I want to display the users input as green, and their output as red.
View 2 Replies
View Related
Jul 19, 2013
How to combine the if statements?
cout<<"Enter a sale number"<<endl;
cin>>rec.sale;
if(cin.fail())
{
cout<<"Enter a number"<<endl;
cin>>rec.sale;
}
[Code]...
View 13 Replies
View Related
Feb 1, 2013
How to use library management inputs
View 2 Replies
View Related
Feb 23, 2013
Make a C++ Program that will use nested if else and any looping statement to display the following a certain number of times depending on how many times the user wants it to do so.
Input Values:
1. Name of employee
2. Position in the company
3. No. of hours worked
4. Rate per hour
5. Overtime hours
Required Output:
No. Name Position Rate per No. of hours Basic No. of overtime Overtime
hour worked Pay hours Pay
1. Juan Manager 160 140 22400 10 2100
Computations:
basic pay = no. hours worked x rate per hour
overtime = overtime hours x 150% of rate per hour
Just asking how can I input the name, position, rate per hour, overtime hours and hours worked in a horizontal manner?
Because I need to achieve the required output.
View 1 Replies
View Related
May 26, 2014
How to make an input with a string thats part of an if statement. How I think it should be done :
#include <iostream>
#include <string>
using namespace std;
int main() {
string choose;
[Code] .....
But I get a strange warning (not an error, but something that is like "just letting you know" i suppose) and when i enter in ss or SS or aa or AA, it breaks my app.
View 7 Replies
View Related
Mar 16, 2014
How to get user inputs into an array. I have to get 10 user inputs into the array and I'm trying to use a loop but once I run it it crashes whenever you input the first value. This is my absolute first time working with arrays and I've been trying to do research
#include <stdio.h>
#define SIZE 10
void Input(const int array1[]);
void Calculations(int array1[], int average);
void Output(int array1[], int average);
[Code]....
View 2 Replies
View Related
Oct 6, 2014
my lecture notes had this chunk of code on it. Which was the way to let a user enter not more than 40 different numbers , and save it into an array. The code is as follows :
#include <stdio.h>
#define MAX 41
void readData(int num[] , int * count);
[Code]...
In the function readData , why is n being scanned before and during the while loop?
View 1 Replies
View Related
Nov 26, 2013
It's not something trivial but I would like to know the best way to process multiple outputs, for example:
Input
First line of input will contain a number T = number of test cases. Following lines will contain a string each.
Output
For each string, print on a single line, "UNIQUE" - if the characters are all unique, else print "NOT UNIQUE"
Sample Input
3
DELHI
london
#include<iostream>
Sample Output
UNIQUE
NOT UNIQUE
NOT UNIQUE
So how can I accomplish outputs like that? My code so far is:
Code:
int main(int argc, char *argv[]) {
int inputs, count=0;
char str[100];
char *ptr;
scanf("%d",&inputs);
[Code] ....
But the above will obviously print the output after each input, so I want to know how can I achieve the result given in the problem. Also another thing I want to know is, I am using an array of 100 char, which it can hold a string up to 100 characters, but what do I have to do if I want to handle string with no limit? Just declaring char *str is no good, so what to do?
View 5 Replies
View Related
Jul 31, 2013
I have recently looked into a self created project where I wanted to compare user input against a list of strings in an external file. That has since been completed to my great satisfaction, however it did throw up some interesting issues in my knowledge and understanding of user input..What is the best way to pick up user input i.e scanf,stdin etc. and when should either be used and can a mixture of types be used, and if so, when and why.
A quick program to take different input methods and display differnt output method (obviously corresponding i.e scanf/printf - fgets/fputs)
My first pothole came when I have setup the method for scanf - fine. Then I setup the method for fgets(test,100,stdin) for example and the fgets method no longer picks up stdin from the user..
View 3 Replies
View Related