join to piece of a program 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: join to piece of a program 2

  1. #1
    Join Date
    May 2017
    Posts
    175

    join to piece of a program 2

    SO this is my code . I wanted thee program to take a certai number of car from user and display the result in a table but its actually not please run it to see what I mean

    Code:
     double calculate_charges ( double h ) {
    
      if ( h == 24 ) {
    
    	  return 10.00;
      }
      else if ( h <= 3 ) { 
    	  
    	  return 2.00;
      }
      else { 
    
    	  double chg = 3 + (( h - 3 ) *0.50);
    
          return chg;
      }
    }
    
    int main ()
    {
    
    int c; double hours;
    
    do {
    		
    		cout << "\nPlease enter the number of cars :\n" << endl;
    	        cin >> c;
    		
    	  }while ( c <= 0 && cout <<"Wrong choicet!" );
    
    		for ( int i = 1 ; i <= c ; ++i ) {
    		
    	    do {
    		cout << "\nPlease enter the number of hours by car " << i << " today :\n" << endl;
    		cin >> hours;
    
    		}while ( hours > 24 && cout << "Wrong choice!" );
    		
    		    for ( int j = 1 ; j <= i ; j++ ) 
    		 
    		  
    			cout<<"\n"; // added this in order  to separate so you can see what is wrong clearly
    			cout << "Car\t\tHours\t\tCharge\n"
    			     << "----\t\t------\t\t-------" << endl
    				 << i <<"\t\t"<< hours << "\t\t" << calculate_charges ( hours );
    		
                          system ( "pause" );
                          return 0;
    }
    Last edited by david16; June 30th, 2017 at 01:45 PM.
    Share on Google+

  2. #2
    Join Date
    May 2017
    Posts
    175

    Re: join to piece of a program 2

    Can you please tell me how to display all result together at once and not one by one ? thx
    Share on Google+

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,835

    Re: join to piece of a program 2

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.4.4)
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)