I know I don't have to keep typing std::cout or std::cin because I didn't use the "using namespace std;" at the beginning, but does it matter? I would also like to know if my coding looks ok, and is it ok for a begginner? I have no errors or problems with it just asking from a more experienced programmer. By the way I couldn't think of nothing creative so I just tried coding in random questions, lol, so it might sound kinda stupid... Heres my Code:
int main(void)
{
std::string Line(80,'_'), Fnam, Lnam, Color; //Fnam stands for First Name, and Lnam stands for Last Name;
unsigned int Age(0), Day(0), Year(0); //All three variables contain no value 'yet'
signed int Money = sizeof(char); //char is a one byte character
signed int Blood = sizeof(char);
signed int Water = sizeof(char);
signed RESULT;
std::cout<<("::About U Information:: (AUI) Version 1.01"); //This is the header name and version
std::cout<<std::endl<<Pyramid<<std::endl<<Line; //This is the Logo for the intro
NL();
std::cout<<"Before we begin, you must be 18 years old or older to proceed...\n"; //Question
std::cout<<"Please enter your age:> "; std::cin>>Age; //User input
if (Age < 18) //if statement for user to be eligible or un-eligible to continue
{
std::cout<<"\n\tYou are un eligible to continue beyond this point\n\tdue to your age being "<<Age<<" years old.\n";
std::cout<<"\tYou will now be exited out of the prompt!\n";
Wait();
return 0;
}
std::cout<<"\n\tAge confirmed and accepted, you may continue...\n"; //Acceptance Phrase
NL();
NL();
std::cout<<"Press |Enter| to Continue\n";
Wait();
system("Cls"); //Clears Data
std::cout<<("::About U Information:: (AUI) Version 1.01");
std::cout<<std::endl<<Pyramid<<std::endl<<Line;
std::string Gender;
std::cout<<"\nAre you a (Male) or a (Female)? :> "; std::cin>>Gender;
NL();
std::cout<<"Enter only your First Name:> "; std::cin>>Fnam;
NL();
std::cout<<"Enter only your Last Name:> "; std::cin>>Lnam;
NL();
std::string Month;
std::cout<<"Enter the Name of the Month you were born on :> "; std::cin>>Month;
NL();
std::cout<<"Enter the Year you were born on :> "; std::cin>>Year;
NL();
std::cout<<"Enter the Day of the Month you were born on :> "; std::cin>>Day;
NL();
std::cout<<"Enter the name of your favorite Color:> "; std::cin>>Color;
std::cout<<"\nPress |Enter| to Continue\n";
Wait();
system("Cls");
std::cout<<("::About U Information:: (AUI) Version 1.01");
std::cout<<std::endl<<Pyramid<<std::endl<<Line;
std::cout<<"\n\tFull Name: "<<Fnam<<" "<<Lnam<<"\n";
std::cout<<"\tAge: "<<Age<<"\n";
std::cout<<"\tDate of Birthday: "<<Month<<" "<<Day<<", "<<Year<<"\n";
std::cout<<"\tGender: "<<Gender<<"\n";
std::cout<<"\tPreferred Color: "<<Color<<"\n";
std::cout<<'\t'<<Fnam<<" your first name \""<<Fnam<<"\" contains "<<Fnam.length()<<" characters,\n";
std::cout<<"\tand your last name \""<<Lnam<<"\" contains "<<Lnam.length()<<" characters.\n";
std::cout<<"\nPress |Enter| to Continue\n";
Wait();
system("Cls"); //Clears Prompt Data
std::cout<<("::About U Information:: (AUI) Version 1.01");
std::cout<<std::endl<<Pyramid<<std::endl<<Line;
std::cout<<'\n'<<Fnam<<" you have three options \'Blood\', \'Money\', & \'Water\'\n";
std::cout<<"Which of the three following choices are more important for you to be complete\n";
std::cout<<"\n\tBlood = "<<Blood<<"\n\tMoney = "<<Money<<"\n\tWater = "<<Water<<"\n\n";
std::cout<<"Enter your three importancies from which you think should\ncome first & last in life.\n";
std::cout<<"\n\tEXAMPLE: Money, Water, Blood Or Blood, Money, Water\n\n";
;std::string Name[3];
int i;
for(i=0;i<=2;i++)
{
std::cout<<"\nEnter Your Importance: ";
std::cin>>Name[i];
}
for (i=0;i<=2;i++)
{
std::cout<<'\t'<<Name[i]<<""<<std::endl;
}
I don't know why I use int main(void) but I was watching a couple youtube videos and I read some randoms person comment that said it's good to use int main(void)... I want to understand it more... and vlad what do you mean code tags or else everyone will hate me, lol? code tags... what do you mean I should do code tags?
Well The best way i can explain why void is bad in int main is first of all you return a 0 at the end usually to signify success... so something is not right there because void signifies that you return nothing. Thats probably the easiest explanation for now. But maybe one of the better programmers here can explain better. and yeah alot of the stuff you do certainly works but is just not very standard like the #define NL() std::cout<<'\n'; and is bad practice for when you move unto bigger projects. I linked you great practice problems go slowly through all the tutorials on this site, and if you have questions start a new topic thats what we are here for. But this is a good attempt
Thank you all for your opinions and help because I surely needed that and got the whole concept of code tags and will definitely use it. I have one minor question chipp the way you wrote ++i, is it the samething as i++? is there a reason for why one can either put i++ or ++i?
#include <iostream>
usingnamespace std;
int main(){
int x, y;
x = 10; y = ++x;
cout << "x = 10; y = ++x; y = " << y << endl;
x = 10; y = x++;
cout << "x = 10; y = x++; y = " << y << endl;
return 0;
}
It shows difference :P
And btw, i personaly think thats ugly way to code. #define NL() std::cout<<'\n';
cant you simply use endl macro?
Or... use return 0;rather thanreturn EXIT_SUCCESS;
And for the love of god, why ; at end of #define line?
Also read this:
http://www2.research.att.com/~bs/bs_faq2.html
EDIT: and read this http://en.wikipedia.org/wiki/Computer_programming#Readability_of_source_code
Generally seems that writing "using namespace std::cout" and "using namespace std::cin" is OK, but simply to use use the whole of the std namespace is ill-advised because that allows hundreds (possibly thousdands I'm not sure) of functions to be used, and if you use another namespace, you can come into conflict issues.
I had personally always written "using namespace std::cout" at the beginning of all my codes but I'm still very new to this, and I think I shall change from now on.