Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Calender Creation->given days by user

Posted on 1998-12-24
5
231 Views
Last Modified: 2010-04-02
I need some help with this...it is work for school and i am stuck...the idea is a nested while loop.  This is what i got so far (it isnt much)

// Borland Turbo C++ for Windows 4.5 (In Windows95 operating system)

// [42 days monat]
// calender making program
// user puts in how many days in month, and user puts in what is the first
// day of this week, (if sunday = day 1, etc.)
// main idea: to utilize a nested loop (while or for)


/*
      KALENDERMACHER PRO V1.0 PRE-BETA

      NESTED-A-ROONY WHILE OR FOR-A-ROO LOOP-A-DOO LABS

      */

#include <iomanip.h>
#include <iostream.h>

int main()

{
  int days, week, row, col;
  cout << "How many days are in this month: ";
  cin >> days;
  char choice;
  cout << "\nSunday\nMonday\nTuesday\nWednesday\ntHursday\nFriday\nsAturday\n\n";
  // comment for next line, input must be capital as well
  cout << "What is the first day of the month??\n\nPlease choose the capitalized lettter.  Thank you.\n\n>> ";
  cin >> choice;


  cout <<"\nSu Mo Tu We Th Fr Sa\n";

  switch (choice)

  {
       case 'S' :
       {
             cout << setw(2);
             for (int i=1; i<=7; i++)
              cout << i << setw(3);
                    break;
       }

       case 'M' :

       {
                   cout << setw(5);
                   for (int i=1; i<=6; i++)
                    cout << i << setw(3);
                                break;
       }

       case 'T' :
       {
             // s m t w t f s
             // - - 1 2 3 4 5
             cout << setw(8);
             for (int i=1; i<=5; i++)
                    cout << i << setw(3);

             for (week = row; week <= days; ++ week)
                  {
                    cout << week;
                    if (week % 7 == 5)
                         cout << endl;
                  }
                         break;
       }

       case 'W' :
       {

             cout << setw(11);
             for (int i=1; i<=4; i++)
                    cout << i << setw(3);

                          break;
       }

       case 'H' :
       {
             cout << setw(14);
             for (int i=1; i<=3; i++)
                    cout << i << setw(3);

                          break;
       }

       case 'F' :
       {
             cout << setw(17);
             for (int i=1; i<=2; i++)
                    cout << i << setw(3);

                                break;
       }

       case 'A' :
       {
             cout << setw(20);
             for (int i=1; i<=1; i++)
                    cout << i << setw(3);

                          break;
       }

       default : cout << "Du bist ein Blödkopf!  Inputten ein validen Karaktörnen";
  }
  return 0;
}

0
Comment
Question by:weinrj
  • 3
  • 2
5 Comments
 

Expert Comment

by:tangyw
ID: 1181012
I think there are 2 main problems in your program.
1. Only display the first week. I think this is not your wanted.
2. case 'T' :
    {
    // s m t w t f s
    // - - 1 2 3 4 5
    cout << setw(8);
    for (int i=1; i<=5; i++)
      cout << i << setw(3);

->    for (week = row; week <= days; ++ week)
->    {
->      cout << week;
->      if (week % 7 == 5)
->    cout << endl;
->    }
    break;
    }

   What does 'for (week ..)' mean ? Why only in "case 'T'"?

If you want to display the all days of the month, please modify it like this.
1. main( )
   {
       int i;    // add define i, I need it to display the remain  days

2. delete 'int' in the 'for' statement( in EACH 'case') , because need the value of i after the 'for' statement.
   for ( int i=i; i<=....)
         ^^^
          |___ Delete it!

3. Delete 'for (week = row; week <= days; ++ week) {...}'. It does NOT work, because did not initialize the 'row'.

4. Add these lines as below before the ' return 0;'

   cout << setw(2);  // Do as you did
   // Print the date for 'i'
   for ( week=i, col=1; week<=days; week++, col++) {
     cout << week << setw(3);
     if ( col%7 == 0 ) { // Is it Saturday ?
       cout << endl;     // Yes
       if ( j < 9 )      // Only want to display it as you did.
         cout << setw(2);
     }
   }
   return 0;            // This is your line.


Is it OK?

 
0
 

Author Comment

by:weinrj
ID: 1181013
i am rejecting this for now...it is a stupid computer assignment for school...we were given a week and that is a weeks work for me...i dont get C++.   Case 'T' was the first day of the lab...the loop there was my teachers suggestion.  I just need a nested while loop for the program requirements.  this is what he wants, asking, How many days in this month, and what day is the day #1.  It will then display a table of numbers.  (this is a mock calender, nothing useful, just for a grade.)  I am stuck and would like to know if you are willing to make this program and send me the source code and if possible the compiled exe file to me via email at jwnrb@cybernex.net.  Thank you.
0
 

Expert Comment

by:tangyw
ID: 1181014
Check you Email pls.
-Tang
0
 

Accepted Solution

by:
tangyw earned 120 total points
ID: 1181015
Hi weinrj
Is that right?

(Only want to lock this question)
0
 

Author Comment

by:weinrj
ID: 1181016
thank you.  i will give you 25 bonus points for being very efficent....it works well.  (i was hoping for the printing part to be a nested while, but for would work as well, thanks!)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MSVCR80.dll crash 2 141
IdTelnet1DataAvailable handler freezes the Application 4 84
SNMP error No Such Object available on this agent at this OID 3 301
What is sub-make ? 2 71
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

838 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question