Thread: C++ Question with uncomplete answer..anyone can solve it?

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    6

    Lightbulb C++ Question with uncomplete answer..anyone can solve it?

    (1)Let the user enter the ISBN, the system will trace the title and price of the book automatically. The system should check whether the book is in the stock or not. If it is not, please let the user to enter again.
    (2)Allow a customer to buy more than one item from the bookshop.
    (2)Calculate and print the bill. The billing amount should include 5% tax.

    Here The Sample Output:

    Welcome to Billy’BookShop

    Please enter the ISBN: 0128
    The title is C++ How to Program
    The Price is RM 108.90

    Do you wish to continue? y/n
    y

    Please enter the ISBN: 0992
    The title is Introduction to Java Programming
    The Price is RM 89.60

    Do you wish to continue? y/n
    n

    Your Receipt:

    0128 RM 108.90
    0992 RM 89.60
    Total RM 198.50
    Tax RM 9.92

    Total RM 208.42

    THANK YOU!!!


    Code:
    #include <iostream> 
    #include <fstream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    { 
        double ISDN ; 
        char title;
        float price; 
    	 
    	cout<<"---Welcome To Billy's Bookshop---\n";
    	cout<<"Please enter the ISDN: ";
    	cin>>ISDN;
    
    	if (ISDN==12)
    	{
    		cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM 108.90"<<endl;
    	}
        if (ISDN==98)
    	{
    		cout<<"The Title is Introduction to Java Programming"<<endl<<"The Price is RM 89.60"<<endl;
    	}
    	else
    	{		
    		cout<<"Not Valid"<<endl;
    	}
    	return 0; 
    }
    Hope someone will complete the answer...see who got it?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by jason07
    Hope someone will complete the answer...see who got it?
    This program is not much of a challenge. But nobody will do your homwork.
    Ask specific questions and we will be glad to answer them.
    Kurt

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    6
    Quote Originally Posted by ZuK
    This program is not much of a challenge. But nobody will do your homwork.
    Ask specific questions and we will be glad to answer them.
    Kurt

    Help me pls...i have try to do some...just need some help...
    see the code below...does any mistakes??
    i dunno where should the do while loop put...

    Code:
    #include <iostream> 
    #include <fstream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    { 
        double ISDN ; 
        char title;
    	float price;
    	int continues;
    	char ans;
    	 
    	cout<<"---Welcome To Billy's Bookshop---\n";
    	cout<<"Please enter the ISDN: ";
    	cin>>ISDN;
    
    	if (ISDN==12)
    	{
    		cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM 108.90"<<endl;
    	}
        if (ISDN==98)
    	{
    		cout<<"The Title is Introduction to Java Programming"<<endl<<"The Price is RM 89.60"<<endl;
    	}
    	else
    	{		
    		cout<<"Not Valid"<<endl;
    	}
    
    	
    	do
    	{
           cout<< "Do you want to continue (Y/N)?\n";
           cout<< "You must type a 'Y' or an 'N'.\n";
           cin >> ans;
    	}
    	while((ans !='Y')&&(ans !='N')&&(ans !='y')&&(ans !='n'));
    
    	
    	return 0; 
    }

  4. #4
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Code:
    int main()
    { 
        double ISDN ; 
        char title;
    	float price;
    	int continues;
    	char ans = 'Y';
    	 
    	cout<<"---Welcome To Billy's Bookshop---\n";
    
    while((ans !='N') || (ans !='n') && (ans =='y') || (ans =='Y')) 
    {
    	cout<<"Please enter the ISDN: ";
    	cin>>ISDN;
    
    	if (ISDN==12)
    	{
    		cout<<"The Title is C++ How to Program"<<endl<<"The Price is RM 108.90"<<endl;
    	}
        if (ISDN==98)
    	{
    		cout<<"The Title is Introduction to Java Programming"<<endl<<"The Price is RM 89.60"<<endl;
    	}
    	else
    	{		
    		cout<<"Not Valid"<<endl;
    	}
    
           cout<< "Do you want to continue (Y/N)?\n";
           cout<< "You must type a 'Y' or an 'N'.\n";
           cin >> ans;
    }
    
    	
    	return 0; 
    }
    Isnt this your second topic about this? reread c++ tutorials and books, they tell you the basics of how to do a program like this.

    At this point I'd suggest adding an counter that adds +1 after each book is bought, and you use an array to keep track of the books bought, ie. array[counterhere].
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > double ISDN ;
    1. There's a big difference between ISBN and ISDN
    2. std::string ISBN;
    would be a much better data type in my opinion.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    6
    Quote Originally Posted by Salem
    > double ISDN ;
    1. There's a big difference between ISBN and ISDN
    2. std::string ISBN;
    would be a much better data type in my opinion.

    can show me how is the coding look like???

    this part...as u say the ISDN

    ISDN n ISBN wat is the different??

    Question:=

    Welcome to Billy’BookShop

    Please enter the ISBN: 0128
    The title is C++ How to Program
    The Price is RM 108.90

    Do you wish to continue? y/n
    y

    Please enter the ISBN: 0992
    The title is Introduction to Java Programming
    The Price is RM 89.60

    Do you wish to continue? y/n
    n

    help me with the coding for this part....

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    6
    Quote Originally Posted by Dae
    Isnt this your second topic about this? reread c++ tutorials and books, they tell you the basics of how to do a program like this.

    At this point I'd suggest adding an counter that adds +1 after each book is bought, and you use an array to keep track of the books bought, ie. array[counterhere].

    Help me up with the 1st part pls...i hv try it not works...
    not i dun wan to do it...but dunno...so i ask for ur help...

    Question:

    Welcome to Billy’BookShop

    Please enter the ISBN: 0128
    The title is C++ How to Program
    The Price is RM 108.90

    Do you wish to continue? y/n
    y

    Please enter the ISBN: 0992
    The title is Introduction to Java Programming
    The Price is RM 89.60

    Do you wish to continue? y/n
    n


    pls help me with codings...

    thanks a millions....

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > can show me how is the coding look like???
    Pretty much like you have now
    some cin to read input
    some if() to compare it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by jason07
    w
    ISDN n ISBN wat is the different??
    learn to use google to find common answeres.

    ISDN

  10. #10
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by jason07
    Help me up with the 1st part pls...i hv try it not works...
    not i dun wan to do it...but dunno...so i ask for ur help...

    thanks a millions....
    I assumed you could fix it yourself after seeing that much. Are you self-teaching yourself? or is this homework - what it looks like.

    use this while statement instead:

    Code:
    while((ans != 'N' || ans != 'n') && (ans == 'y' || ans =='Y'))
    What its doing there is the while statement will continue if the answer choice is not 'n' or 'N', and will continue if its 'y' or 'Y'.

    and look at your if and else statements, it should be

    Code:
    else if (ISDN==98)
    The reason is because it was printing out the else statement if you happened to enter 12. There rest would follow that trend also:

    Code:
    if (ISDN==12) {
    
    } 
    else if (ISDN==98) {
    
    }
    else if (ISDN==34) {
    
    }
    else if (ISDN==43) {
    
    }
    else if (ISDN==74) {
    
    }
    else {
    //this is only printed if none of the above are chosen
    }
    Read what I write, try to understand whats going on before messing around with it not knowing what you're doing, or go study more.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple question, anyone can answer me..
    By jayhor in forum C++ Programming
    Replies: 6
    Last Post: 11-01-2006, 05:20 AM
  2. long question; short answer <templates>
    By misplaced in forum C++ Programming
    Replies: 4
    Last Post: 09-25-2004, 05:34 AM
  3. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  4. stupid question need quick answer
    By mbsupermario in forum C++ Programming
    Replies: 5
    Last Post: 10-14-2002, 06:17 AM
  5. Replies: 1
    Last Post: 01-23-2002, 03:34 AM