Write your question here. How do i wrape numbers around in my calandar
I have been working on this program for hours and cannot find out how to make the numbers loop around after they hit saturday. They either go way passed it to the right or if i add and endl; they go up and down.
// This is how my output looks like (except they curve around they just go forever to the right:
Number of days: 31
Offset: 0
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
// This is my program, what do i need to add? please help
#include <iostream>
#include <iomanip>
using namespace std;
/*************************************************
* Prompt for days
**********************************************/
int GetDays()
{
int days;
cout << "Number of days: ";
cin >> days;
return days;
}
/***************************************************
* compute offset
***************************************************/
int ComputeOffSet()
{
int num = 0;
cout << "Offset: ";
cin >> num;
return num;
}
/***************************************************
* add display
*****************************************************/
void display(int days, int num)
{
cout << " Su Mo Tu We Th Fr Sa" << endl;
num = num * 3 + 3;
for (int s = 0; s < num; s++)
{
cout << " ";
}
for (int i = 1; i <= days; i++)
{
num += i;
cout << setw(4) << i;
}
cout << endl;
}
/**********************************************************************
*This will output everything
***********************************************************************/
int main()
{
int days = GetDays();
int num = ComputeOffSet();
display(days, num);
return 0;
}
also is there a way to do it without strings do you know? i havent really been taught that yet but and do not want to be graded down because of that, even though they make life so much easier lol.
Strings are easiest, character arrays ( more particularly char*'s) another possibility but you can't get away from it and another is to 'slice' pieces out of a single "SuMoTuWeThFrSa"" string of characters. ( The magic is there's really no magic! )
void display(int days, int num)
{
cout << " Su Mo Tu We Th Fr Sa" << endl;
for (int s = 0; s < num; s++)
{
cout << " ";
}
for (int i = 1; i <= days; i++)
{
cout << setw(3) << i;
}
cout << endl;
}
can i ask you for a huge favor please, i have been working on this all day today and i am so close, i cant figure out what i am doing wrong, my offset at zero should start on monday,
//This is my output:
a.out
Number of days: 31
Offset: 5
Su Mo Tu We Th Fr Sa
1
2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Number of days: 31
Offset: 3
Su Mo Tu We Th Fr Sa
1 2 3
4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
#include <iostream>
#include <iomanip>
usingnamespace std;
/*************************************************
* Prompt for days
**********************************************/
int GetDays()
{
int days;
cout << "Number of days: ";
cin >> days;
return days;
}
/***************************************************
* compute offset
***************************************************/
int ComputeOffSet()
{
int num = 0;
cout << "Offset: ";
cin >> num;
return num;
}
/***************************************************8
* add display
*****************************************************/
void display(int days, int num)
{
cout << " Su Mo Tu We Th Fr Sa" << endl;
int we = num;
num = num * 3 + 3;
for (int s = 0; s < num; s++)
{
cout << " ";
}
int i = 1;
for (i; i <= (7-we); i++)
{
num += i;
if (i%(7-we)==0)
cout << endl;
cout << setw(4) << i;
}
for (int j = 0; i <= days; j++, i++)
{
num += j;
if (j%7==0)
cout << endl;
cout << setw(4) << i;
}
cout << endl;
}
/*****************************************************************
* This will output everything!
*****************************************************************/
int main()
{
int days = GetDays();
int num = ComputeOffSet();
display(days, num);
return 0;
}