On-line: гостей 0. Всего: 0 [подробнее..]
Программисты всех стран, объединяйтесь!

АвторСообщение



ссылка на сообщение  Отправлено: 15.11.14 21:00. Заголовок: writing structures


If anyone could help me with this, that would be great. I am not really sure what to do.
My problem states:
Pass the address of a Date structure variable to the days() function. Write a program in main() than inputs the month, day, and year from the user, writing the inputs into a Date structure variable, call your days() function and display the result. Use the following date structure:
struct date
{
int month;
int day;
int year;
};

In writing this function, use the convention that all years are 360 days and each month consist of 30 days. The function should return the number of days for any date structure passed to it.

Спасибо: 0 
ПрофильЦитата Ответить
Ответов - 4 [только новые]





ссылка на сообщение  Отправлено: 15.11.14 21:27. Заголовок: As I understand you ..


As I understand you need to write function days() declared like
 
int days( date *d );


Or if it is a C program then

 
int days( struct date *d );




Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 15.11.14 21:59. Заголовок: yeah sorry, it is C ..


yeah sorry, it is C programming. I forgot to mention that.

Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 15.11.14 23:30. Заголовок: This is what i have ..


This is what i have so far, not sure where to take it from here
struct date
{
int month;
int day;
int year;
};

int main()
{
int monthMain, dayMain, yearMain; //declaring the int variables
int days;
int yearCalc;
printf("Enter a Month: "); //requesting user to input the month
scanf("%d", &monthMain); //accepting the user input for month
printf("Enter a Day: "); //requesting user to input the day
scanf("%d", &dayMain); //accepting the user input for day
printf("Enter a Year: "); //requesting user to input the year
scanf("%d", &yearMain); //accepting the user input for year
yearCalc = 1900 * 360;
yearMain = (yearMain * 360) - yearCalc;
if(monthMain == 1)
{
monthMain = 0;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 2)
{
monthMain = 30;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 3)
{
monthMain = 60;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 4)
{
monthMain = 90;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 5)
{
monthMain = 120;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 6)
{
monthMain = 150;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 7)
{
monthMain = 180;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 8)
{
monthMain = 210;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 9)
{
monthMain = 240;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 10)
{
monthMain = 270;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 11)
{
monthMain = 300;
days = monthMain + dayMain + yearMain;
}
if(monthMain == 12)
{
monthMain = 360;
days = monthMain + dayMain + yearMain;
}
printf("the date you entered = %d days", days);
return 0;
}

int days( struct date *d );


Спасибо: 0 
ПрофильЦитата Ответить



ссылка на сообщение  Отправлено: 15.11.14 23:34. Заголовок: All these calculatio..


All these calculations that you do in main you need to transfer in function days.

Also instead of numerous if statements you could define an array with number of days before a given month.

Спасибо: 0 
ПрофильЦитата Ответить
Ответ:
1 2 3 4 5 6 7 8 9
большой шрифт малый шрифт надстрочный подстрочный заголовок большой заголовок видео с youtube.com картинка из интернета картинка с компьютера ссылка файл с компьютера русская клавиатура транслитератор  цитата  кавычки моноширинный шрифт моноширинный шрифт горизонтальная линия отступ точка LI бегущая строка оффтопик свернутый текст

показывать это сообщение только модераторам
не делать ссылки активными
Имя, пароль:      зарегистрироваться    
Тему читают:
- участник сейчас на форуме
- участник вне форума
Все даты в формате GMT  3 час. Хитов сегодня: 3
Права: смайлы да, картинки да, шрифты да, голосования нет
аватары да, автозамена ссылок вкл, премодерация откл, правка нет