You just have to run it and play with it.
some stuff you may need to know...
when running console programs at a console, you can redirect a text file into them and it is as if you typed it. this is great to run with the same input over and over but only type it up once. its more or less the same in unix and windows too; in windows a.exe < file.txt will do it. (and > will do the reverse and stuff all couts into a text file for you).
once you can easily run it over and over, start playing with the formatting.
'\t' is tab. you can use this to align things (on top of the width etc formatting of cout).
learn to print doubles with N decimal places and a fixed width so they look nice in a table.
if you want to clear the screen before making a pretty output, a simple way is:
system(command) ... on windows, that is system("cls") ... I forget unix, clear or something similar
if you want to keep the info but add some spacing, just cout << endl a few times to split the input and output visually.
You need to pay more attention to the output of your compiler. The reason you don't see any change is that the code doesn't even compile. So you were running the old compiled code.
You need to put std:: in front of the endl's. And you have accidentally added a / at the end of line 27 above.
@handyPandy, Stop bickering? Who are you to order me around. Your namby pamby “Hope this helps” bullshit every time sounds like an Alice in Wonderland grovel from the phoniest of Tin Men.
you don't need {} around non-blocks, and this will get you into trouble as a habit because it will scope variables inside the {} pairs and that will break things if you did not do it by intent. The extra ;s on the brackets are also not useful. This stuff is visual clutter at best and buggy under some conditions (if you get ; happy and add extras you will invariably poke one on a loop or if statement and break something).
the 2 endls should have added 2 blank lines (spaces are something else, and go between words, in programming terms).
This makes me agree with dutch, are you sure you recompiled a clean version with the 2 endls in it?
/ I think is legal but you don't want it there. I think its the line continue 'operator', but I am not double checking, and I havent used that since macros became mostly obsolete.
you can double down. cout << endl << endl; or slightly better, cout << "\n\n";
If you compile by hand, delete the executable first thing when you start a compile. If you use an IDE, you can set it to do this on many.
Really? I get several errors and a couple of warnings.
1 2 3 4 5 6 7 8 9
main.cpp||In function ‘int main()’:|
main.cpp|16|warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘longunsignedint’} [-Wsign-compare]|
main.cpp|27|error: expected primary-expression before ‘/’ token|
main.cpp|28|error: expected primary-expression before ‘}’ token|
main.cpp|30|error: ‘endl’ was not declared in this scope|
main.cpp|30|note: suggested alternative:|
/opt/gcc-8.1.0/include/c++/8.1.0/ostream|590|note: ‘std::endl’|
main.cpp|38|warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘longunsignedint’} [-Wsign-compare]|
||=== Build failed: 3 error(s), 2 warning(s) (0 minute(s), 0 second(s))
The program is only as good as what you tell it to do.
Have a look at this:
1 2 3 4 5 6 7 8 9 10 11 12 13
//Formatted Table
//std::cout << std::string(40, ' ') << "Birth\n";
std::cout << " Name Birth City Birth Year\n";
std::cout << std::string(47, '_') << '\n'; // <--- Does the same as the next line.
//std::cout << "________________________________________________\n";
for (size_t index = 0; index < MAXSIZE; index++)
std::cout
<< std::left
<< std::setw(20) << name[index] /*<< " "*/
<< std::setw(20) << birthCity[index] /*<< " "*/
<< std::right // <--- Better to set numbers to the right.
<< std::setw(4) << birthYear[index] << '\n';
On lines 10 and 11 I used the setw's to control the spacing. The end of the line is not needed unless you want extra space. Since you are not using a floating point number the setw in line 13 could be omitted and then line 12 would not be needed.
Sorry you right it’s not running. But why when I try to run it on visual studio it goes ? Is it running the last successful build ?
Yes. If you build an executable program, and then you hit compile on any compiler, and your recent edits make this new compile fail, you can still run the executable program from earlier. And, it won't do the new stuff that did not compile in the old program version's executable.