What does this program mean?!

the questions I have about this program are; what does key word string mean and how is it used in this program? can someone break this down and explain this ? MUCH APPRECIATED!

-ryan


#include <iostream>
#include <string>
using namespace std;


int main ()

{

string dayOfWeek;////////?

int birthYear;
int birthMonth;
int birthDay;
int total = 0;


////////////////////////////////////// INPUT ////////////////////////////////////////////

cout <<"Enter the year of your birth ===> ";
cin >> birthYear;
cout << endl;


if ( (birthYear <= 1900) || (birthYear >= 2000) )
//////// why arent there any else statements?



{
cout << "Must choose a year between 1900 - 2000\n";
cout << "for this program to run properly.\n\n";
cout << "\n\n";
}

cout <<"Enter the month of your birth ===> ";
cin >> birthMonth;
cout << endl;

cout <<"Enter the day of your birth ===> ";
cin >> birthDay;
cout << endl << endl << endl;

///////////////////////////////////// PROCESSING /////////////////////////////////////////


///////////these calculations make no sense? what does the % (mod) sign do here?


birthYear = birthYear % 1900;

total = birthYear / 4;

total = birthYear + total;
total = birthDay + total;


if ( (birthMonth == 4) || (birthMonth == 7) )

{
total = total + 0;
}

if ( (birthMonth == 1) || (birthMonth == 10) )

{
total = total + 1;
}

if ( (birthMonth == 5) )

{
total = total + 2;
}

if ( (birthMonth == 8) )

{
total = total + 3;
}

if ( (birthMonth == 2) || (birthMonth == 3) || (birthMonth == 11) )

{
total = total + 4;
}

if ( (birthMonth == 6) )

{
total = total + 5;
}

if ( (birthMonth == 9) || (birthMonth == 12) )

{
total = total + 6;
}

if ( (birthYear % 4 == 0) && (birthMonth == 1) || (birthMonth == 2) )

{
total = total - 1;
}


if ( (total % 7 == 1) )

{
dayOfWeek = "Sunday";
}


if ( (total % 7 == 2) )

{
dayOfWeek = "Monday";
}


if ( (total % 7 == 3) )

{
dayOfWeek = "Tuesday";
}


if ( (total % 7 == 4) )

{
dayOfWeek = "Wednesday";
}

if ( (total % 7 == 5) )

{
dayOfWeek = "Thursday";
}

if ( (total % 7 == 6) )

{
dayOfWeek = "Friday";
}


if ( (total % 7 == 7) )

{
dayOfWeek = "Saturday";
}

total = total / 7;

/////////////////////////////////////// OUTPUT //////////////////////////////////////////////////////////

cout << " ********** You were born on a " << dayOfWeek << " **********";
cout << endl << endl << endl << endl;
cout << "Press enter to continue....";


cin.ignore(2,' ');

return 0;
}
The "string" contains a string of characters, and in the sample program it is used to hold the day of the week the user is born on and print it on the console.

An if() statement isn't always necessarily followed by an else / else if. An else / else if will only execute if the previous conditions are not met, and in this case, it is not needed.

Modulo (%) is the sign for remainder. i.e. 5 % 2 = 1, because there is a remainder of 1. This can be useful for checking if a number is even or not - i.e. n % 2 returns 0 if it is even, 1 if it is odd.
THANKYOU FOR YOUR HELP! THIS CLASS IS HARD! WHAT DOES THE PROCESSING PART OF THIS MEAN? THE TOTAL + 1 , +2 +3 AND SO ON?
closed account (S6k9GNh0)
1) Don't use caps.
2) Use [code] tags.
3) Its not difficult at all. Simply part of paying attention in class. Plus, there are hundreds of online references to help you out.
4) There is no such thing as a keyword called string.
5) There is however a STL container called string inside of the std:: namespace.
6) If you can't figure out the processing part on your own, you need to get out of the class and probably go back to middle school since this is basic algebra with variables. The smallest amount of studying would help you with any syntax that you aren't sure about.
Last edited on
yeah thats true caps are loud. i was just xcited for any help or responses? what online help is there that you use?
Topic archived. No new replies allowed.