How to Validate input and check length

I am trying to write a program that take input from the user to make a

Page 1 of 1

2 Replies - 3674 Views - Last Post: 02 October 2008 - 11:48 AM Rate Topic: -----

#1 lady_blu4u   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-September 08

How to Validate input and check length

Posted 02 October 2008 - 11:38 AM

#include <iostream>
#include <cstdlib>

using namespace std;

int main ()
{

int callone = 0;
cout <<"Please enter the nimber you would like to call! ex. 4056783456";
cin >> callone;

if (cin.fail() )
{
cout <<"Error: Bad input/n";
return 1;
}



double minservice, minserviceday, minservicenight;
double daycharge = 0.0, nightcharge = 0.0;
char servicecode;
double charges;

//input service code

switch(------------)
{case 'r':
case '----':
//enter the number of minutes the telephone service is used:

case 'p':
case '-------':

default:
//deisplay message "your service code is invalid"
return 0;
}
cout <<setiosflags (ios::fixed) <<setprecision(2);
if (servicecode == ---------
servicecode == ---------)
{cout <<setiosflags (ios::left) <<setw(24) <<-------------;
cout<<setw(9) <<resetiosflags (ios::left) << "Regular"<<endl;
cout<<setiosflags (ios::left) <<setw(24) <<"Minutes used:";
cout<<setw(9) <<resetiosflags (ios::left) <<------------ <<endl;
}
else
{cout<<setiosflags (ios::left) <<setw(24) <<------------;
cout<<setw(9) <<resetiosflags (ios::left) <<------------ <<endl;
cout<<setiosflags (ios::left) <<setw(24)<<"Minutes used:";
cout<<setw(9) <<resetiosflags (ios::left) <<---------- <<endl;

}
return 0;
}

MOD EDIT: Please :code:
Thanks, gabehabe :)

Is This A Good Question/Topic? 0
  • +

Replies To: How to Validate input and check length

#2 ajwsurfer   User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 385
  • Joined: 24-October 06

Re: How to Validate input and check length

Posted 02 October 2008 - 11:43 AM

Maybe you could finish your question in the body of the message and just start by using the code that you have working?

#include <iostream>
#include <cstdlib>

using namespace std;

int main ()
{

  int callone = 0; 
  cout <<"Please enter the nimber you would like to call! ex. 4056783456";
  cin >> callone;

  if (cin.fail() )
  {
	cout <<"Error: Bad input/n";
	return 1;
  }
}


This post has been edited by ajwsurfer: 02 October 2008 - 11:43 AM

Was This Post Helpful? 0
  • +
  • -

#3 lady_blu4u   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 07-September 08

Re: How to Validate input and check length

Posted 02 October 2008 - 11:48 AM

I am suppose to be writing a program that takes ten numbers with the area code 405 520 620 550 650 and generate a call connection time using rand() to generate an unsigned integer between 0 and RAND_MAX and than in return display call statistics total revenue. I am trying to approach this by breaking it down and so far this is what I have

#include <iostream>
#include <cstdlib>

using namespace std;

int main ()
{

  int callone = 0; 
  cout <<"Please enter the nimber you would like to call! ex. 4056783456";
  cin >> callone;

  if (cin.fail() )
  {
	cout <<"Error: Bad input/n";
	return 1;
  }
}


[/quote]
1.input from users a phone number
405 (2 cents per second basic_rate)
520 (1.25 * basic_rate)
550 (1.25 * basic_rate)
620(1.75 * basic_rate)
650(1.75 * basic_rate)

double basic_rate = .2 * second
double 520 = 1.25 * basic_rate
double 550 = 125 * basic_rate
double 620= 1.75 * basic_rate
double 650=1.75 * basic_rate


int callone = 0;
cout<<”Please enter the number you would like to call starting with area code ex.4056233456”;
cin >> callone;


minimize input validatoin 4056677345

if (cin.fail())
{
cout<< “Error: Bad input/n”;
return 1;
}


check length= 10
while lop:
while (callone = )
{
callone =
#include <cstdlib>
RAND_MAX
rad(0- RAND_MAX )

restrict the times to set values 1s-120s (use arithmetic operators)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1