Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,228 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,886 people online right now. Registration is fast and FREE... Join Now!




Writing simple calendar

 
Reply to this topicStart new topic

Writing simple calendar, how to force numbers to start on new line?

bels
14 Mar, 2007 - 04:19 PM
Post #1

New D.I.C Head
*

Joined: 14 Mar, 2007
Posts: 4


My Contributions
Hi. I gotta finesh this calendar but I'm having a problem with forcing numbers to start new line inside while statement so output looks like this:
IPB Image
Can you guys tell me hoe to do it?

here is the code, code is very simple rolleyes.gif
CODE
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int month, days, day, count=1;
    cout<<"\t\t\t\tCalendar\n";
    cout<<"Enter number of month: ";
    cin>>month;
    cout<<"Enter day of the month (1 for Sanday, 2 for Monday...): ";
    cin>>day;
    if (month ==1){cout<<"\n\t\t\tJanuary\n\n"; days=31;}
    if (month ==2){cout<<"\n\t\t\tFebruary\n\n"; days=28;}
    if (month ==3){cout<<"\n\t\t\tMarch\n\n"; days=31;}
    if (month ==4){cout<<"\n\t\t\tApril\n\n"; days=30;}
    if (month ==5){cout<<"\n\t\t\tMay\n\n"; days=31;}
    if (month ==6){cout<<"\n\t\t\tJun\n\n"; days=30;}
    if (month ==7){cout<<"\n\t\t\tJuly\n\n"; days=31;}
    if (month ==8){cout<<"\n\t\t\tAogust\n\n"; days=31;}
    if (month ==9){cout<<"\n\t\t\tSeptember\n\n"; days=30;}
    if (month ==10){cout<<"\n\t\t\tOctober\n\n"; days=31;}
    if (month ==11){cout<<"\n\t\t\tNovember\n\n"; days=30;}
    if (month ==12){cout<<"\n\t\t\tDecember\n\n"; days=31;}
    
    cout<<"\nSan\tMon\tTue\tWen\tThu\tFri\tSat\n";
    while (count<=days){
        switch(day){
        case 1:
            cout<<count<<"\t";break;
        case 2:
            cout<<"\t"<<count<<" "; break;
        case 3:
            cout<<"\t\t"<<count<<" "; break;}// by the way case 3 does not display correctly at all...

        count++;}
    return 0;
}

I recently started to study C++ snd I've been banging my head for two days now wub.gif

This post has been edited by bels: 14 Mar, 2007 - 04:19 PM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Writing Simple Calendar
14 Mar, 2007 - 05:25 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
When do you want to force a newline?
User is online!Profile CardPM
+Quote Post

bels
RE: Writing Simple Calendar
14 Mar, 2007 - 05:56 PM
Post #3

New D.I.C Head
*

Joined: 14 Mar, 2007
Posts: 4


My Contributions
I want to force it right after the Saturday(Because there 7 day in a week and Saturday is last day) so numbers will be right under each day of the week. Did you look at the sreenshot of the output? On screenshot you may see the problem...!!!
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Writing Simple Calendar
14 Mar, 2007 - 06:03 PM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
I would suggest then that you want insert a line break every time your count variable reaches a multiple of a certain number. wink2.gif
User is online!Profile CardPM
+Quote Post

bels
RE: Writing Simple Calendar
14 Mar, 2007 - 08:15 PM
Post #5

New D.I.C Head
*

Joined: 14 Mar, 2007
Posts: 4


My Contributions
QUOTE(Amadeus @ 14 Mar, 2007 - 07:03 PM) *

I would suggest then that you want insert a line break every time your count variable reaches a multiple of a certain number. wink2.gif

Well yeah. How can I do it?
User is offlineProfile CardPM
+Quote Post

bels
RE: Writing Simple Calendar
19 Mar, 2007 - 05:33 PM
Post #6

New D.I.C Head
*

Joined: 14 Mar, 2007
Posts: 4


My Contributions
ph34r.gif So what no one here knows?
Today I tried to modify the code but it still does not work can you tell me please what is my mistake? Please take a look at this code:
CODE
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int month, days, day, count=1;
    cout<<"\t\t\t\tCalendar\n";
    cout<<"Enter number of month: ";
    cin>>month;
    while (month>12 || month<1){
    cout<<"\nYou have entered invalid number of month!";
    cout<<"Please reenter number of month"; cin>>month;}
    
    cout<<"Enter first day of the month (1 for Sunday, 2 for Monday...): ";
    cin>>day;
    while(day>7 || day<1){
    cout<<"You have entered invalid day of the month! ";
    cout<<"Please reenter first day of the month: ";
    cin>>day;}
    if (month ==1){cout<<"\n\t\t\tJanuary\n\n"; days=31;}
    if (month ==2){cout<<"\n\t\t\tFebruary\n\n"; days=28;}
    if (month ==3){cout<<"\n\t\t\tMarch\n\n"; days=31;}
    if (month ==4){cout<<"\n\t\t\tApril\n\n"; days=30;}
    if (month ==5){cout<<"\n\t\t\tMay\n\n"; days=31;}
    if (month ==6){cout<<"\n\t\t\tJun\n\n"; days=30;}
    if (month ==7){cout<<"\n\t\t\tJuly\n\n"; days=31;}
    if (month ==8){cout<<"\n\t\t\tAogust\n\n"; days=31;}
    if (month ==9){cout<<"\n\t\t\tSeptember\n\n"; days=30;}
    if (month ==10){cout<<"\n\t\t\tOctober\n\n"; days=31;}
    if (month ==11){cout<<"\n\t\t\tNovember\n\n"; days=30;}
    if (month ==12){cout<<"\n\t\t\tDecember\n\n"; days=31;}
    cout<<"\nSun\tMon\tTue\tWen\tThu\tFri\tSat";
    for (;day<=7;day++){
        if (day==1){ cout<<" ";}
        if (day==2){ cout<<"\t";}
        if (day==3){ cout<<"\t\t";}
        if (day==4){ cout<<"\t\t\t";}
        if (day==5){ cout<<"\t\t\t\t";}
        if (day==6){ cout<<"\t\t\t\t\t";}
        if (day==7){ cout<<"\t\t\t\t\t\t";}}
    for (;count<=days; count++)
    {cout<<count<<"\t";}
    
    return 0;
    }


I think the mistake is somewhere within first for statement
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Writing Simple Calendar
19 Mar, 2007 - 06:07 PM
Post #7

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You can find when a number is at a specific multiple by using Modulus division.

http://www.cprogramming.com/tutorial/modulus.html

By using mod division and dividing by 7 (for 7 days in the week), when the result is equal to zero then insert a newline using a cout statement.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:02PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month