Thread: please,helpe me in correcting this code!!

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    4

    Unhappy please,helpe me in correcting this code!!

    Hi everybody ,
    I know very little about this high language,
    for my studying field in BA is far & different
    from the PC programming languages,which I’m studying
    it to take a diploma in it. So , kindly I want your help.
    I really spent two days in searching the e-books and
    other forum to find a way or a rule, but I failed.
    I wrote this broken code ,broken, because many of it’s
    statements are not completed .Please help me, and who
    wants to help me in solving them has to read these four
    items carefully;
    1- My program run on Microsoft Visual C++ 6.0.
    2- I wrote my questions between the explanation
    marks(/* */),to specify the place of my questions.
    3- My program must include only
    the <iostrem.h> library; why?,because this what I only
    did study, in this quarter.
    4- I must use the( do/while , for )as loop
    statements and (switch/case), (if/else if)as conditional
    and selective statements).
    5- I left the condition blank as in while( ) empty .

    Code:
    #include <iostream.h>
    void main()
    { 
    int PartNo,Required_Qauntity ;
       // here is a two dimensional array 
    int x[3][3]={10,50,100,20,60,200,30,70,300};
    cout<<"PartNo\ tQuantityNo\tPartPrice\n";
    for(int i=0;i<3;i++)
    { cout<<"\n";
    for(int j=0;j<3;j++)
    cout<<x[i][j]<<"\t";
    }
    do
    {
    cout<<"\nEnter the part number:\n\n ";
     cin>> PartNo; 
    /* the program must search this PartNo in the array,.and 
    if it is found , 
     it must go to the 3rd (do/while)statement, to ask the user 
    to "Enter the Required_Qauntity",
     but if it isn't found the program must go to the first 
    statement.."enter PartNo",How??*/
      do
      {
     for ()
     {
    // how can I complete this condition (if it's correct!!)
       if(PartNo = = 
      {
    //if the PartNo is exist then		  
     cout<<"this PartNo is exist, and it's:\n"<<  ( display the 
    entered PartNo)<<"\n";
     break;}
    }
    	 
    /* if the PartNo not found then print the next output & go 
    to the first statement.." Enter the PartNo" */
    cout<<" PartNo is not  exisit\n";
    
     }while (  );
    
     do
     { cout<<"\n";
     cout<<"Enter the Required_Qauntity:\n";
    cin>>Required_Qauntity;
    /*the program must search the array to find if this RQ is
     exist or no,If yes ,thenit must display it. If  No,it prints 
    "This Qauntity is not available" and 
     goes back to the the first  statement .." Enter the PartNo".*/
    cout<<"The Required_Qauntity is not avaliable";
    }while(  );
    /* what is the condition here in the basic (do/while)*/
    }while(  );
    }
    thank you

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Based on your code and a few of my own assumptions, I came up with this:

    Code:
    #include<iostream>
    
    using namespace std;
    
    int main()
    {
    
         int PartNo, Required_Quantity;         
         // here is a two dimensional array 
         int x[3][3]={10,50,100,20,60,200,30,70,300};
         char choice; 
         
         cout<<"PartNo\tQuantity      Price\n";
         
         for(int i=0;i<3;i++)
         {
              cout << endl;                
              for(int j=0; j<3; j++)         
                   cout<<x[i][j]<<"         ";
         }
    
         do
         {
              cout<<"\n\nEnter the part number: ";
              cin>> PartNo; 
              
              /* the program must search this PartNo in the array,.and 
              if it is found , 
              it must go to the 3rd (do/while)statement, to ask the user 
              to "Enter the Required_Qauntity",
              but if it isn't found the program must go to the first 
              statement.."enter PartNo",How??*/
     
              int index;  
              bool found = false;              
              for (index=0; index<3 && !found; index++)
        
                  if(PartNo == x[index][0])
            
                      found = true;        
    
              // how can I complete this condition (if it's correct!!)
              if(found)
              {
    
                   //if the PartNo is exist then		  
                   cout<<"\nthis PartNo is exist, and it's $"<< x[--index][2] <<"\n";              
                   cout<<"\nEnter the Required_Qauntity: ";
                   cin>>Required_Quantity;
                   
                   /*the program must search the array to find if this RQ is
                   exist or no,If yes ,thenit must display it. If  No,it prints 
                   "This Qauntity is not available" and 
                   goes back to the the first  statement .." Enter the PartNo".*/
                
                   if(Required_Quantity > x[index][1])
                   
                       cout<<"\n\aThe Required_Qauntity is not avaliable";
         
                   else
         
                       cout<<"\nThe Required_Quantity is available";
         
              }
         
              else
              {
                    /* if the PartNo not found then print the next output & go 
                    to the first statement.." Enter the PartNo" */
                    cout<<"\nPartNo is not  exisit\n";
              }
         
              cout << "\n\nWould ye' like to try again? (Y/N): " ;
              cin >> choice;     
         
         }while(choice == 'Y' || choice == 'y');
    
    return 0; 
    }
    Even if this is not exactly what you need, hopefully it's enough to start you on the right track.
    Last edited by The Brain; 01-23-2006 at 01:17 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    4

    Thanks Mr.The Brain,but..

    Thanks Mr.The Brain, I really appreciate your help, I benefited from your code, but displaying an element from the array mustn’t be with bool ,it must be by using loop as (do/while) and select statements, could you give keywords help me in solving it by one of these ways, just clues.
    I formatted my program but it doesn’t do the following mathematical statement.
    Quantity * Price = …
    How can I correct this rule( x[++index][2] ) to give me the specific element from the array? x[++index][2]
    “The price of the sold quantity is $"<<" "<<Required_Quantity<<"*"<<x[++index][2] <<"="<<Required_Quantity*x[++index][2]<<"\n";

    This is the code:
    Code:
    #include<iostream.h>
    
    
    
    int main()
    {
    
         int PartNo,Price;
    		 int Required_Quantity;
    		 int Quantity; 
    	 int answer;
    	  
         // here is a two dimensional array 
         int x[3][3]={10,50,100,20,60,200, 30,70,300};
    
         
         cout<<"PartNo\t  Quantity      Price\n";
         
         for(int i=0;i<3;i++)
         {
              cout << endl;                
              for(int j=0; j<3; j++)         
                   cout<<x[i][j]<<" ";
         }
    
    	
         e: cout<<"\n\nEnter the part number:\n ";
             
    		cin>> PartNo; 
              
    
              int index;  
              bool found = false;              
              for (index=0; index<3 && !found; index++)
        
                  if(PartNo == x[index][0])
            
                      found = true;        
    
              if(found)
             
    		  {
    	  
                   cout<<"\nthis PartNo is exist, and it's"<<" "<< x[--index][0] <<"\n";              
                   cout<<"\nEnter the Required_Qauntity: ";
                   cin>>Required_Quantity;
                  
    			  	
    				  if(Required_Quantity > x[index][1] || Required_Quantity <=0)	 
    			  
    			
    				  {cout<<"\nThe Required_Quantity is not available";
    		 
    			 goto e;
    				  }
    
    
    		   else	
    			   
             
    		  
                     cout<<"\nThe Required_Quantity is available at "<<x[--index][1]<<"\n"; 
    		  
    			     
                  
    		  
    		  
    		  
    		  do
    		  {
                   
    		  cout<<"\nDo you want to continue the selling process?Please choose the answer.\n";
    		  cout<<"1- YES.\n";
    
              cout<<"2- NO.\n";
    		   cin>>answer;
    
    		  switch (answer)
    		  {
    		  case 1:
    			 
    			  { if(answer=='y' || answer=='Y')
    
                   
                  cout<<"\n";
    			  cout<<"The price of the sold qauntity is"<<" "
    			<<Required_Quantity<<"*"<<x[++index][2] <<"="<<Required_Quantity*x[++index][2]<<"\n";
    		      cout<<"the part number is "<<PartNo<<",the avaliable qauntity is"<<Quantity<<","<<
    			"the remain qauntity is"<<Quantity<<"-"<<Required_Quantity<<"="<<Quantity-
    			Required_Quantity<<"and the price of the sold qauntity is $"<<" "
    			<<Required_Quantity<<"*"<<x[++index][2] <<"="<<Required_Quantity*x[++index][2]<<"\n";
    			  }
    			  
    	    	case 2:
    			if(answer=='n' || answer=='N')
    			
                   goto e;
    			  
    			
    		  }
    		
    	    	do
    			 {
                cout<<"\nDo you want to make another selling process?Please choose the answer.\n";
    		  cout<<"1- YES.\n";
    
              cout<<"2- NO.\n";
    		   cin>>answer;
    
    		  switch (answer)
    		  {
    		  case 1:
    			 
    			  if(answer=='YES' || answer=='yes')
    				  
    				  cout<<"\tgo:\n";
    			 goto e;
    
    			  
    			 case 2:
                     
    				 
    				
    				break; 
    				
    		  }
    
    		  }while(answer=='n');
    
    		  }while(answer=='n');
    		   }
    
    	else
              {
                cout<<"\nPartNo is not  exisit\n";
    			goto e ;
    	}
    
    	 
    		  
    
    
    }

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    I will offer you more help with your code if you give me your a/s/l
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    And on that note - closed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM