Dec 5, 2012 at 4:55pm UTC
hello i got a homework to do a c++ calendar for november 2012 , but something wrong with that code the numbers it the third line move right. and are not under ther 2 lines ..help me please
#include <iostream>
using namespace std;
void main()
{ int x=0;
cout<<"S "<<"M "<<"T "<<"W "<<"T "<<"F "<<"S "<<endl;
for (int i=-3; i<=30; i++)
{ if (i<=0)
cout<<" ";
else
cout<<i<<" ";
x++;
if (x%7==0)
cout<<endl;
}
cin>>x;
}
Dec 5, 2012 at 6:28pm UTC
Because on the third line there are two digits in the numbers, and not just one.
1 2 3
4 5 6 7 8 9 <- one digit
10 11 12 13 14 <- two digits
you'll need to compensate by adding an additional space.
Last edited on Dec 5, 2012 at 6:29pm UTC
Dec 5, 2012 at 6:57pm UTC
ok and where to add it?thanks
Dec 5, 2012 at 7:36pm UTC
I would add it before the "i"
Your adding a space, it's your homework, spend a few mins and try some things.
If you want a answer, use code tags at least. - Thx-