CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 4 of 6 FirstFirst 123456 LastLast
Results 46 to 60 of 85
  1. #46
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    Now the problem is that I should pass all my arrays to function and put it outside the main

  2. #47
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    hello there . So I've changed my prog plan design to make it easier for me . My task in this part of code is to display a map of the array as shown in code below but I have a prob . I actually wanted the values to be stored by column but its doing it by row . It should only fill first column with 1 and then cout that message "Sorry there is not more place .. Any idea what I've done wrong ?

    Code:
     {
    	
    	const int col = 1;
    	bool found = false;
    
    	for (int row = 1 ; row < 16 ; ++row)
    	if (spot_1 [col][row] == 0) {
    	
    cout << "There is a place reserved for you in spot 1 , the first column , row number " << " " << row << "." << endl;
    
    	  string choice;
    
    	do {
    	   cout << "\nDo you want to take that Place? Y/N.\n" << endl;
    	   cin >> choice;
    	   cout << "\n" << endl;
    
    	transform(choice.begin(), choice.end(), choice.begin(), toupper);
    	} while (choice != "Y" && choice != "YE" && choice != "YES" && cout << "Wrong input!\n" << endl);
    
    	cout << "Have a nice day!\n" << endl;
    
    	if (choice[0] == 'Y') {
    	spot_1 [col][row] = 1; 
    		found = true;
    		
    	
    	 cout<<"Big Parking  :\n"
         <<"--------------\n\n"; 
     
    	const int colmn = 15;
    	const int row = 13;
    
    for( int x = 1; x < colmn ; ++x ) {
        
    	  for (int i = 1 ; i < row ; ++i) {
        
    	cout<< spot_1 [x][i];
    	}
    cout<<endl;
    } 
    cout<<"\n";	
    }
    break;
    	
        if (!found)
    		
    	cout << "Sorry ,There is no more places , But you can go to :";
     }
    }
    break;

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

    Re: mulfunction of array

    There are a couple of issues.

    There are inconsistencies with the dimensions of the array - at one point it has 16 rows and in another it has 13?? Why not have const ints at the beginning specifying the number of rows and columns and use that through the code - you only do this before the array display?

    There is also a close bracket issue which if the code was properly formatted and indented would become apparent.

    Also don't forget that the first element of an array is 0. The array loops in the code start at 1?
    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++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #49
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    No the array get first 0 in first column and prompt it to user if user said yes that 0 will be changed to 1 till row 16 and when this column is all set to 1 it should go out of loop display map and cout the message "Sorry there is no more places..." . But its not working like this . Its doinn it row by row and doesnt stop

  5. #50
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    I want to display all array where first column has stored 1 . it should stop on first column and go to the message there is no more places . because the other 0 are going to be used for another task u see?

  6. #51
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: mulfunction of array

    ...and what debugging of the program has been done? When a program compiles OK but doesn't work as expected and as designed, then you use the debugger to trace through the program to see the execution trace through the program and the values of the variables as the program is executed.
    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++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #52
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    So will post the debugging of the code post #47 so u can see what I actually need to do and what is done jus a second

  8. #53
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    So this is the result when I debug the program

    Code:
     Do you want to take that Place? Y/N.
    
    y
    
    
    Have a nice day!
    
    Big Parking  :
    --------------
    
    110000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    you see what I mean I want it to store first column all the rows then stop and cout<<"Sorry no more places available for you ..." but its storing row by row and doesn't stop till the end of array. how can we fix the code in post #47 to do the output I'm expecting? thanks

  9. #54
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: mulfunction of array

    Quote Originally Posted by david16 View Post
    So will post the debugging of the code post #47 so u can see what I actually need to do and what is done jus a second
    It's not a question of what I can see you need to do, but what you see you need to do. We've not here to debug your program and/or write it for you. We've here to provide appropriate advice and support.
    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++23 Compiler: Microsoft VS2022 (17.6.5)

  10. #55
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: mulfunction of array

    Quote Originally Posted by david16 View Post
    So this is the result when I debug the program

    Code:
     Do you want to take that Place? Y/N.
    
    y
    
    
    Have a nice day!
    
    Big Parking  :
    --------------
    
    110000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    you see what I mean I want it to store first column all the rows then stop and cout<<"Sorry no more places available for you ..." but its storing row by row and doesn't stop till the end of array. how can we fix the code in post #47 to do the output I'm expecting? thanks
    That is not debugging. Debugging is using the debugger to step through the code to determine where the execution isn't as expected. What has been posted is just the output from the program.
    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++23 Compiler: Microsoft VS2022 (17.6.5)

  11. #56
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    debugging get succeed ? that doesn't doesn't help me find out the error ?!

  12. #57
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    if the debugger didn't work I can't even launch the code right ??? Its working but not the way I want I tried to change for loop section but couldn't find out the error u see? the code post #47 is working on debugger what not the way I told you
    Last edited by david16; May 18th, 2017 at 10:59 AM.

  13. #58
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: mulfunction of array

    Quote Originally Posted by david16 View Post
    debugging get succeed ? that doesn't doesn't help me find out the error ?!
    I'm not understanding you. What compiler/ide are you using? The debugger is part of the compiler/ide package.

    Using the debugger is exactly what will help to find why the code isn't working as expected.

    This code based upon post #47 displays the expected output from the logic of the code. It may not work as required from the design - but that is a design issue and not a coding issue. If this output isn't as required, then you need to re-visit the program design and change the design. Once you have a correct design then you code the program from that design.

    Code:
    #include <string>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
    	const int colmn = 15;
    	const int row = 13;
    
    	int spot_1[colmn][row] = { 0 }
    	;
    	const int col = 1;
    	bool found = false;
    
    	for (int rw = 1; rw < row; ++rw)
    		if (spot_1[col][rw] == 0) {
    			cout << "There is a place reserved for you in spot 1 , the first column , row number " << " " << rw << "." << endl;
    
    			string choice;
    
    			do {
    				cout << "\nDo you want to take that Place? Y/N.\n" << endl;
    				cin >> choice;
    				cout << "\n" << endl;
    
    				transform(choice.begin(), choice.end(), choice.begin(), toupper);
    			} while (choice != "Y" && choice != "YE" && choice != "YES" && choice != "N" && choice != "NO" && cout << "Wrong input!\n" << endl);
    
    			cout << "Have a nice day!\n" << endl;
    
    			if (choice[0] == 'Y') {
    				spot_1[col][rw] = 1;
    				found = true;
    
    				cout << "Big Parking  :\n"
    					<< "--------------\n\n";
    
    				for (int x = 1; x < colmn; ++x) {
    					for (int i = 1; i < row; ++i) {
    						cout << spot_1[x][i];
    					}
    					cout << endl;
    				}
    				cout << "\n";
    			}
    			break;
    		}
    
    		if (!found)
    				cout << "Sorry ,There is no more places , But you can go to :";
    }
    Last edited by 2kaud; May 18th, 2017 at 03:56 PM.
    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++23 Compiler: Microsoft VS2022 (17.6.5)

  14. #59
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    Its kind of working but without
    Code:
    break
    after this part its will loop to the other part next after and If I put the
    Code:
    break
    it will prompt after the menu always same spot "first column , row number 1." without looping its king of not storing just for first choice then loop on it each time

  15. #60
    Join Date
    May 2017
    Posts
    182

    Re: mulfunction of array

    I have 3 separate spots it should not exit first spot until all rows of column 1 are filled with 1 . Looks like we can't loop and display the map at same time because it will keep looping on first one . This is the whats I get only the first 1 in both cases with or without break .

    Code:
    100000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    000000000000
    the main purpose is to be able to fill for each user who choose "Yes" 1 instead of 0 displaying each time the map . this will only happen to first line . If no more 0 on first line , its should then tell user "Sorry , there is no more places.." and then he should get directed to the next spot and so on u see what's the problem with it ?
    Last edited by 2kaud; May 18th, 2017 at 12:35 PM.

Page 4 of 6 FirstFirst 123456 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured