Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef ORIGINAL /* see below for updated version */
- // i am learn this simple code but he tell me id returned 1 exit status
- #include<iostream>
- #include<cstdlib>
- namespace month_name
- {
- void jan();
- void feb();
- void print();
- //...
- }
- namespace month_number
- {
- enum month_year{
- jannuary =1 , febuary , mar
- };
- month_year month;
- }
- void month_name::jan()
- {int cnt=1;
- for(size_t i=1; i<31; i++)
- {cnt++;
- std::cout << i << "\t";
- if(cnt == 7)
- {std::cout << std::endl;}
- else if (cnt == 14)
- {std::cout << std::endl;}
- else if(cnt == 21)
- {std::cout << std::endl;}
- else if(cnt == 28)
- {std::cout << std::endl;}}}
- void month_name::feb()
- {int cnt=1;
- for(size_t i=1; i<30; i++)
- {cnt++;
- std::cout << i << "\t";
- if(cnt == 7)
- {std::cout << std::endl;}
- else if (cnt == 14)
- {std::cout << std::endl;}
- else if(cnt == 21)
- {std::cout << std::endl;}
- else if(cnt == 28)
- {std::cout << std::endl;}}}
- void month_name::print()
- {switch(month_number::month)
- {case month_number::jannuary:
- month_name::jan();
- break;
- case month_number::febuary:
- month_name::feb();
- break;
- default:
- std::cerr << "not enough" << std::endl;}
- #else
- // i am learn this simple code but he tell me id returned 1 exit status
- // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- // cleaned up and working:
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- namespace month_name {
- void jan();
- void feb();
- void print();
- //...
- }
- namespace month_number {
- enum month_year {
- january = 1, febuary, march,
- };
- month_year month;
- }
- void month_name::jan() {
- int cnt = 0; // 1;
- for (size_t i = 1; i < 32; i++) {
- cnt++;
- // std::cout << i << "\t";
- std::cout << std::setw(5) << i; // << "\t";
- if (cnt == 7) {
- std::cout << '\n'; // std::endl;
- }
- else if (cnt == 14) {
- std::cout << '\n'; // std::endl;
- }
- else if (cnt == 21) {
- std::cout << '\n'; // std::endl;
- }
- else if (cnt == 28) {
- std::cout << '\n'; // std::endl;
- }
- }
- }
- void month_name::feb() {
- int cnt = 0; // 1;
- for (size_t i = 1; i < 30; i++) {
- cnt++;
- // std::cout << i << "\t";
- std::cout << std::setw(5) << i; // << "\t";
- if (cnt == 7) {
- std::cout << std::endl;
- }
- else if (cnt == 14) {
- std::cout << std::endl;
- }
- else if (cnt == 21) {
- std::cout << std::endl;
- }
- else if (cnt == 28) {
- std::cout << std::endl;
- }
- }
- }
- void month_name::print() {
- switch (month_number::month) {
- case month_number::january:
- month_name::jan();
- break;
- case month_number::febuary:
- month_name::feb();
- break;
- default:
- // std::cerr << "not enough" << std::endl;
- std::cout << "not enough" << std::endl;
- break;
- }
- }
- int main(int argc, char const * argv[]) {
- month_number::month = month_number::month_year::january;
- month_name::print();
- std::cout << '\n' << '\n';
- month_number::month = month_number::month_year::febuary;
- month_name::print();
- std::cout << '\n' << '\n';
- month_number::month = month_number::month_year::march;
- month_name::print();
- std::cout << '\n' << '\n';
- return 0;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement