Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > C/C++ Базы данных
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 16.11.2014, 17:21   #1
sasha1212
Пользователь
 
Регистрация: 11.03.2014
Сообщений: 13
По умолчанию База данных турфирмы

Я написал простенькую базу данных,но она не работает.Кто может подсказать где ошибки в программе
Код:
#include <stdio.h>
#include <conio.h>

void print(int);
void input_data();
void output_data();
void change_data(int);
void search_data();
void finish_application(void);


struct touring
{char country[50];
 char city [50];
 int tour_duration ;
 int cost ;
};
int n;
struct touring tour[8];

void print(int i)
{
printf("The record number: %d\n",i);
printf("Country: %s\n",tour[i].country);
printf("City: %s\n",tour[i].city);
printf("Number of days: %d\n",tour[i].tour_duration);
printf("Cost: %d \n",tour[i].cost);
	
}


void input_data()
{int i;
  for(i=1;i<=n;i++)
   {
    printf("Enter country of tour:");
   	scanf("%s",&tour[i].country);
   	printf("\n Enter city of tour:");
   	scanf("%s",&tour[i].city);
   	printf("\n Enter number of days of tour:");
   	scanf("%d",&tour[i].tour_duration);
   	printf("Enter cost of tour:");
   	scanf("%d",&tour[i].cost);
   	
   }
   
}

int main(void)
{int p;
printf("Welcome to Data Base \n");
printf("\n\t Enter 1 if you want to enter data\n");
printf("\n\t Enter 2 if you want to look at data\n");
printf("\n\t Enter 3 if you want to change data\n");
printf("\n\t Enter 4 if you want to finish work with application\n");
scanf("%d",&p);
 switch(p)
  {case 1 :
  	      input_data;
  	      break;
   case 2:
   	      output_data;
   	       break;
   case 3:
             change_data;
			 break;	       
   case 4:
   	        finish_application();
   	        break;
   default: printf("\n\t Any of points isn't chosen");
  }
  getch();
  return 0;
}
    void change(int i)
    {int a;
    printf("Enter data for change\n");
    printf("1.Country of tour\n");
    printf("2.City of tour\n");	
    printf("3.Number of days of tour\n");
    printf("4.Cost of tour\n");
    	
    scanf("%d",&a);
	switch(a)
	{
	 case 1:
	      {
	      	printf("Enter new country\n");
	      	scanf("%s",&tour[i].country);
	      	break;
	      }
	 case 2  :
	   {
	   	printf("Enter new city\n");
	      	scanf("%s",&tour[i].city);
	      	break;
	   }
	  
	  case 3:
	  {printf("Enter new number of days opf tour\n");
	      	scanf("%d",&tour[i].tour_duration);
	      	break;
	  } 
	case 4:
	{printf("Enter new cost of tour\n");
	      	scanf("%d",&tour[i].cost);
	      	break;
	}  
	      
	}	
    	
    	
    }

void search_data()
{ 
  int n=0;
  int i=0;
  int d=0;
  char b[100];
  printf("Enter 1 for search by country\n");
  printf("Enter 2 for search by city\n");
  printf("Enter 3 for search by number of days of tour\n");
  printf("Enter 4 for search by cost of tour\n");	
  scanf("%d",&n);
  switch(n)
  {
    case 1:
    	   {
    	   	printf("Enter country \n");
    	   	scanf("%s",&b);
    	   	for(i=0;i<k;i++)
    	   	    if(tour[i].country==b)
    	   	        print(i);
    	   	        break;
    	   }
  	case 2 :
  		{
    	   	printf("Enter city \n");
    	   	scanf("%s",&b);
    	   	for(i=0;i<k;i++)
    	   	    if(tour[i].city==b)
    	   	        print(i);
    	   	        break;
    	   }
  	case 3 :
  		{
    	   	printf("Enter number of days of tour \n");
    	   	scanf("%s",&b);
    	   	for(i=0;i<k;i++)
    	   	    if(tour[i].tour_duration==b)
    	   	        print(i);
    	   	        break;
    	   }
  	case 4 :{
    	   	printf("Enter cost of tour \n");
    	   	scanf("%s",&b);
    	   	for(i=0;i<k;i++)
    	   	    if(tour[i].cost==b)
    	   	        print(i);
    	   	        break;
    	   }
  	
  }	
	
	
}


void output_data()
{int i;
  	for(i=1;i<=n;i++)
  	 {
  	 	printf("Country of tour:%s\n",&tour[i].country);
  	 	printf("City of tour:%s\n",&tour[i].city);
  	 	printf("Number of days of tour :%d\n",&tour[i].tour_duration);
  	 	printf("Cost of tour:%d\n",&tour[i].cost);
  	 }
  }

void finish_application()
{
	exit (0);
}
sasha1212 вне форума Ответить с цитированием
Старый 05.12.2014, 15:25   #2
netpolice
Форумчанин
 
Аватар для netpolice
 
Регистрация: 14.02.2013
Сообщений: 222
По умолчанию

Я конечно с Сями токо разбираюсь, но вообще при программировании использования глобальных переменных это не айс.
Так Вы здесь

Цитата:
int cost ;
};
int n;
struct touring tour[8];
Объявили n...
Далее в функциях

Цитата:
void input_data()
{int i;
for(i=1;i<=n;i++)
{
printf("Enter country of tour:");
scanf("%s",&tour[i].country);
printf("\n Enter city of tour:");
scanf("%s",&tour[i].city);
printf("\n Enter number of days of tour:");
scanf("%d",&tour[i].tour_duration);
printf("Enter cost of tour:");
scanf("%d",&tour[i].cost);

}

}
Ее используете, а слабо было ее аргументом передать?


Далее здесь:

Цитата:
void search_data()
{
int n=0;
int i=0;
int d=0;
char b[100];
printf("Enter 1 for search by country\n");
printf("Enter 2 for search by city\n");
printf("Enter 3 for search by number of days of tour\n");
printf("Enter 4 for search by cost of tour\n");
scanf("%d",&n);
switch(n)
{
case 1:
Вы ее переобъявляете и используете совсем по другому

А здесь,
Цитата:
scanf("%d",&n);
switch(n)
{
case 1:
{
printf("Enter country \n");
scanf("%s",&b);
for(i=0;i<k;i++)
if(tour[i].country==b)
print(i);
break;
}
как по моему для тех же действий, вообще другая переменная используется, но где Вы ее объявляете?

И потом, где то у Вас массив начинается с 0, где то с 1, в Си все начинается с 0 и это связано с указателями на начало массива.

Последний раз редактировалось netpolice; 05.12.2014 в 15:28.
netpolice вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Postgres: может ли база данных дать отчет, какой язык используется в данных? Blondy SQL, базы данных 2 30.03.2014 06:25
база данных. добавление и удаление данных midiss Общие вопросы Delphi 3 09.12.2011 13:07
База данных и технология хранения данных Kate1 Помощь студентам 2 17.11.2011 23:27
Небольшая база в Open Office База данных. sashaman Фриланс 3 11.04.2010 20:13
База данных с возможностью приема данных из файлов Excel Al_Sha БД в Delphi 6 16.10.2009 15:34