please help with easy problem

This is a discussion on please help with easy problem within the C++ Programming forums, part of the General Programming Boards category; hi guys, This program which is no doubt extremely simple for you people is giving me some headaches. This code ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    84

    please help with easy problem

    hi guys,

    This program which is no doubt extremely simple for you people is giving me some headaches. This code below tells you what day it is ,you then type a number and it tells you what day it will be in that many days.

    Code:
      // what the day was yesterday
    
    #include <iostream>
    using namespace std;
    
    int main(void)
    
    {
    	// declare variables
    	const int week = 7;			// days in week
    	int thatday = 0;			// the day however long ago
    	int today = 4;				// today is 5th day (friday)
    	int daysago = 0;
    	char* weekdays[7] = {"mon","tue","wed","thur","fri","sat","sun"};
    	
    	do{
    	// input information
    
    	cout << endl << endl << "Today is " << weekdays[today] << endl;
    
    	cout << "How many days forward?" << endl;
    
    	cin >> daysago;
    
    	
    
    	// day was what 
    
    	thatday = (daysago + today) % 7;			// % gets remainder
    
    
    
    
    	cout  << weekdays[thatday] << endl;
    
    
    	}while(daysago!=0);
    
    
    
    
    
    	return 0;
    }
    What i am now trying to do is count days ago instead of days ahead.

    I thought this would work

    thatday = (daysago - today) % 7;

    but the program crashes because of the pointer i think.

    What is the best way to achieve this.

    Thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,437
    > thatday = (daysago - today) % 7;
    It does, but I think you'll find that thatday is negative

    Add 7 to it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  2. Relatively easy math problem...
    By gcn_zelda in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-18-2005, 08:48 PM
  3. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  4. Math Problem....
    By NANO in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 11-11-2002, 03:37 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21