Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a C++ Expert!

Join 244,292 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 932 people online right now. Registration is fast and FREE... Join Now!




How to Validate input and check length

 
Reply to this topicStart new topic

How to Validate input and check length, I am trying to write a program that take input from the user to make a

lady_blu4u
2 Oct, 2008 - 10:38 AM
Post #1

New D.I.C Head
*

Joined: 7 Sep, 2008
Posts: 6

cpp
#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.gif
Thanks, gabehabe smile.gif

User is offlineProfile CardPM
+Quote Post


ajwsurfer
RE: How To Validate Input And Check Length
2 Oct, 2008 - 10:43 AM
Post #2

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 320



Thanked: 6 times
Dream Kudos: 50
My Contributions
Maybe you could finish your question in the body of the message and just start by using the code that you have working?

CODE

#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: 2 Oct, 2008 - 10:43 AM
User is offlineProfile CardPM
+Quote Post

lady_blu4u
RE: How To Validate Input And Check Length
2 Oct, 2008 - 10:48 AM
Post #3

New D.I.C Head
*

Joined: 7 Sep, 2008
Posts: 6

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

CODE

#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)



User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 7/4/09 04:04PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month