Thread: Thinking About Programming - A Guide for Beginners ?!?!? little problem

  1. #1
    beginner for now
    Join Date
    Oct 2009
    Posts
    35

    Question Thinking About Programming - A Guide for Beginners ?!?!? little problem

    well the Thinking About Programming - A Guide for Beginners
    I gain trough mail I try it out

    well I could do alone all except to break the program if
    Code:
    (video1 && video2) < 1
    or something like that

    well problem occurs with days

    I gave that lot if cuz if 1 day cannot be 1 days

    so that if you say 1 day it musnt come out 1 days

    and when I try to put in
    Code:
    (video1 && video2) < 1
    it's problem cuz it doesn't look at all other if-s

    how could I repair this problem???
    I'm out of ideas

    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    
    
    
    {
        int x;
        int y;
        int video1;
        int video2;
        cout << "we have 2 available videos to rent\n\n";
        cout << "1 - yes\n_____________________\n1. video costs 2.00$ |\n";
        cout << "2. video costs 3.00$ |\n";
        cout << "_____________________|\n";
        cout << "\n\n\n\n2 - no\n_____________________\nexit                 |\n";
        cout << "_____________________|\n\n\n\n\n";
        cout << "would you like to rent any of videos?\n";
        cin >> x;
        if (x == 2)
              {cout <<"good bye\n";}
        
        else if (x == 1)
             {
                   cout << "\n\nwould you like to rent video1?\n";
                   cout << "this video costs 2.00 $\n";
                   cout << "for how many days would you like to rent video 1\n";
                   cin >> video1;
                   
                   cout << "\n\nwould you like to rent video 2?\n";
                   cout << "this video costs 3.00$";
                   cout << "for how many days would you like to rent video 2\n";
                   cin >> video2;
                   
                   if (video1 > 1)
                   {cout << "\n\n\nvideo 1 is rented for: "<< video1 <<" days\n";}
                   else if (video1 == 1)
                   {cout << "\n\n\nvideo 1 is rented for: "<< video1 <<" day\n";}
                   else
                   {cout << "\n\n\nvideo 1 is not rented\n";}
                   
                   if (video2 > 1)
                   {cout << "video 2 is rented for: "<< video2 <<" days\n\n";}
                   else if (video2 == 1)
                   {cout << "video 2 is rented for: "<< video2 <<" day\n\n";}
                   else
                   {cout << "video 2 is not rented\n";}
    
                   
                   cout << "total cost of video 1 is: " << video1*2.00 << "$\ntotal cost of video 2 is: " << video2*3.00 << "$\n\n";
                   cout << "total cost is: " << video1*2.00 + video2*3.00 <<"$\n";
             }
        system ("pause");
        return 0;
    }
    Last edited by military genius; 10-05-2009 at 12:27 PM. Reason: I did wrong < 0 edit: --> < 1

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Code:
    (video1 && video2) < 1
    I don't think that code does what you think it does. Do you mean to do this instead?
    Code:
    if( video1 < 1 && video2 < 1)
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    beginner for now
    Join Date
    Oct 2009
    Posts
    35
    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    
    
    
    {
        int x;
        int y;
        int video1;
        int video2;
        cout << "we have 2 available videos to rent\n\n";
        cout << "1 - yes\n_____________________\n1. video costs 2.00$ |\n";
        cout << "2. video costs 3.00$ |\n";
        cout << "_____________________|\n";
        cout << "\n\n\n\n2 - no\n_____________________\nexit                 |\n";
        cout << "_____________________|\n\n\n\n\n";
        cout << "would you like to rent any of videos?\n";
        cin >> x;
        if (x == 2)
              {cout <<"good bye\n";}
              
        else if (x == 1)
             {
                   cout << "\n\nwould you like to rent video1?\n";
                   cout << "this video costs 2.00 $\n";
                   cout << "for how many days would you like to rent video 1\n";
                   cin >> video1;
                   
                   cout << "\n\nwould you like to rent video 2?\n";
                   cout << "this video costs 3.00$";
                   cout << "for how many days would you like to rent video 2\n";
                   cin >> video2;
                   if( video1 < 1 && video2 < 1)
                   {cout << "if this couts it has to break every else if-s\n";}
                   
                   if (video1 > 1)
                   {cout << "\n\n\nvideo 1 is rented for: "<< video1 <<" days\n";}
                   else if (video1 == 1)
                   {cout << "\n\n\nvideo 1 is rented for: "<< video1 <<" day\n";}
                   else if (video1 < 1)
                   {cout << "\n\n\nvideo 1 is not rented\n";}
                   
                   if (video2 > 1)
                   {cout << "video 2 is rented for: "<< video2 <<" days\n\n";}
                   else if (video2 == 1)
                   {cout << "video 2 is rented for: "<< video2 <<" day\n\n";}
                   else
                   {cout << "video 2 is not rented\n";}
    
                   
                   cout << "total cost of video 1 is: " << video1*2.00 << "$\ntotal cost of video 2 is: " << video2*3.00 << "$\n\n";
                   cout << "total cost is: " << video1*2.00 + video2*3.00 <<"$\n";
                   
    
             }
        system ("pause");
        return 0;
    }
    well its still does same as before

    problem occurs when I give 0 video1, 0video2
    I have to break the program

    if I give other only else if
    I gain only 1 not 2

    like this
    Code:
    video1 is rented for X day/s/video 1 is not rented
    and I need both
    Code:
    video1 is rented for X day/s/video1 is not rented
    video2 is rented for X day/s/video2 is not rented

  4. #4
    beginner for now
    Join Date
    Oct 2009
    Posts
    35

    Talking

    got it

    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    
    
    
    {
        int x;
        int y;
        int video1;
        int video2;
        cout << "we have 2 available videos to rent\n\n";
        cout << "1 - yes\n_____________________\n1. video costs 2.00$ |\n";
        cout << "2. video costs 3.00$ |\n";
        cout << "_____________________|\n";
        cout << "\n\n\n\n2 - no\n_____________________\nexit                 |\n";
        cout << "_____________________|\n\n\n\n\n";
        cout << "would you like to rent any of videos?\n";
        cin >> x;
        if (x == 2)
              {cout <<"good bye\n";}
              
        else if (x == 1)
             {
                   cout << "\n\nwould you like to rent video1?\n";
                   cout << "this video costs 2.00 $\n";
                   cout << "for how many days would you like to rent video 1\n";
                   cin >> video1;
                   
                   cout << "\n\nwould you like to rent video 2?\n";
                   cout << "this video costs 3.00$";
                   cout << "for how many days would you like to rent video 2\n";
                   cin >> video2;
                   
                   if (video1 < 1 && video2 < 1)
                   {}
                   
                   
                   else if (video1 > 0 || video2 > 0)
                   {
                   if (video1 > 1)
                   {cout << "\n\n\nvideo 1 is rented for: "<< video1 <<" days\n";}
                   else if (video1 == 1)
                   {cout << "\n\n\nvideo 1 is rented for: "<< video1 <<" day\n";}
                   else if (video1 < 1)
                   {cout << "\n\n\nvideo 1 is not rented\n";}
                   
                   if (video2 > 1)
                   {cout << "video 2 is rented for: "<< video2 <<" days\n\n";}
                   else if (video2 == 1)
                   {cout << "video 2 is rented for: "<< video2 <<" day\n\n";}
                   else
                   {cout << "video 2 is not rented\n\n";}
    
                   
                   cout << "total cost of video 1 is: " << video1*2.00 << "$\ntotal cost of video 2 is: " << video2*3.00 << "$\n\n";
                   cout << "total cost is: " << video1*2.00 + video2*3.00 <<"$\n";
                   }
                   
    
             }
        system ("pause");
        return 0;
    }
    Last edited by military genius; 10-05-2009 at 01:41 PM. Reason: change

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    Post

    you could probably simplify your final output section by using the >= operator, you could do away with the seperate '==' test and just use two if else statements
    Code:
     
              else if (video1 > 0 || video2 > 0)
              {              
                    if (video1 >= 1)
                    {
                        cout << "\n\n\nvideo 1 is rented for: "<< video1 <<" day(s)\n";
                    }
                    else
                    {
                        cout << "\n\n\nvideo 1 is not rented\n";}
                    }               
                    if (video2 >= 1)
                    {
                        cout << "video 2 is rented for: "<< video2 <<" day(s)\n\n";
                    }
                    else
                    {
                        cout << "video 2 is not rented\n\n";
                    }  
    
               // results.....
               // results.....
             }
    Last edited by rogster001; 10-06-2009 at 01:22 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Fluid Thinking
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 11-20-2002, 03:29 PM