-
May 17th, 2017, 07:20 AM
#46
Re: mulfunction of array
Now the problem is that I should pass all my arrays to function and put it outside the main
-
May 18th, 2017, 06:58 AM
#47
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;
-
May 18th, 2017, 07:49 AM
#48
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)
-
May 18th, 2017, 08:10 AM
#49
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
-
May 18th, 2017, 08:29 AM
#50
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?
-
May 18th, 2017, 10:38 AM
#51
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)
-
May 18th, 2017, 10:41 AM
#52
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
-
May 18th, 2017, 10:48 AM
#53
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
-
May 18th, 2017, 10:48 AM
#54
Re: mulfunction of array
Originally Posted by david16
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)
-
May 18th, 2017, 10:50 AM
#55
Re: mulfunction of array
Originally Posted by david16
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)
-
May 18th, 2017, 10:52 AM
#56
Re: mulfunction of array
debugging get succeed ? that doesn't doesn't help me find out the error ?!
-
May 18th, 2017, 10:54 AM
#57
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.
-
May 18th, 2017, 11:03 AM
#58
Re: mulfunction of array
Originally Posted by david16
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)
-
May 18th, 2017, 11:39 AM
#59
Re: mulfunction of array
Its kind of working but without after this part its will loop to the other part next after and If I put the 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
-
May 18th, 2017, 11:50 AM
#60
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|