|
-
June 15th, 2016, 03:52 AM
#1
Assignment due in 1 day (Not showing valid) ISBN errors also.
Hey guys i really need help ASAP..
Code:
#include <iostream>
#include <limits>
void draw_menu()
{
std::cout << "******************************************************************\n"
<< "* choose an entry from 1 to 3. *\n"
<< "* [1] validate modulus 11 number *\n"
<< "* [2] validate data *\n"
<< "* [3] quit *\n"
<< "******************************************************************\n";
}
int get_number() // read a valid number from stdin
{
int number ;
if( std::cin >> number ) return number ;
// invalid input, inform the user, clear the input buffer and try again
std::cout << "invalid number. please re-enter\n" ;
std::cin.clear() ;
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
return get_number() ;
}
int get_choice() // display the menu, return valid choice entered by the user
{
draw_menu() ;
const int choice = get_number() ;
if( choice >= 1 && choice <= 3 ) return choice ; // valid choice
return get_choice() ; // invalid choice, try again
}
bool valid_date( int dd, int mm, int yy )
{
// *** TO DO: validate that dd/mm/yy forms a valid date
// if valid, return true
return false ;
}
bool valid_modulo_11( int number )
{
// *** TO DO: validate that number is a valid modulo 11 number
// if valid, return true
return false ;
}
int main()
{
bool quit = false ;
do
{
const int choice = get_choice() ;
switch(choice)
{
case 1:
{
std::cout << "enter modulo 11 number: " ;
const int number = get_number() ;
if( valid_modulo_11(number) ) std::cout << "yes, valid modulo 11 number\n" ;
else std::cout << "that is not a valid modulo 11 number\n" ;
break ;
}
case 2:
{
std::cout << "enter day: " ;
const int dd = get_number() ;
std::cout << "enter month: " ;
const int mm = get_number() ;
std::cout << "enter year: " ;
const int yy = get_number() ;
if( valid_date( dd, mm, yy ) ) std::cout << "valid date\n" ;
else std::cout << "invalid date\n" ;
break ;
}
case 3: quit = true ;
}
} while( !quit ) ;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|