Bandito
03-22-2014, 09:43 PM
// Bono marzo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
const int array_size = 10;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int car[array_size], client, index, menu, number, decision;
/*
car[] = 1 para Toyota, 2 para Jeep, 3 para BMW
client = cantidad de clientes
index= numero unico para saber quien es el cliente
menu = es las opciones del menu
number = despues de darle search y encontrar al usuario se usa ests variable para almacenar el index correcto
*/
float rent[array_size], miles[array_size], deuda;
/*
deuda = la deuda actual del cliente
miles[] = millas recorrida por el cliente
rent[] = dias que el cliente tiene el carro rentado
*/
char flag;//es para controlar y salir del loop
string Fname[array_size], Lname[array_size], se_Fname[array_size], se_Lname[array_size];
/*
Fname[] = nombre del cliente
Lname[] = apellido del cliente
se_Fname[] = el nombre a buscar
se_Lname[] = el apellido a buscar
*/
flag = 'y';
menu = 0;
while (flag == 'y' || flag == 'Y')
{
cout<<"*******************************************"<<endl<<"Enter a number to choose an option:\n"<<"1: Create an user\n"<<"2:Search and display an user data\n";
cout<<"3:Edit an already created user.\n*******************************************";
cin>>menu;//El menu del programa
switch(menu)
{//start of switch
case 1://Creates an user
{
cout<<"How many clients do you want to enter? ";
cin>>client;//number of clients to add in the array
cout<<endl;
for (index =1; index <= array_size; index++)
if (client > 0)
{
if (car[index] < 0)
{//Los datos a crearse de la tabla si el cliente no existe
cout<<"Enter the first name of the client ";
cin>> Fname[index];//El usuario entra el primer nombre del cliente
cout<<"\nEnter the last name of the client ";
cin>>Lname[index];//EL usuario entra el apellido
cout<<"\n**********\nEnter the car model to be rented; Enter a number to choose an option.\n1: 1: Toyota\n2: Jeep\n3:BMW\n**********\n";
cin>>car[index];//el usuario entra el modelo de carro a escoger
miles [index] = 0;//Las millas recorridas; es cero porque el cliente no ha recorrido millas
rent [index] = 0;//Es los dias que el cliente ha tenido el carro; es cero porque el cliente abrio la cuenta hoy
deuda = 0;//Es la deuda existente; es cero porque el cliente no tiene deuda
cout<<endl;
}
else
{
Fname [index] = "0";
Lname [index] = "0";
car [index] = 0;
miles [index] = 0;
rent [index] = 0;
deuda = 0;
}
client--;}
break;
}//end of case 1
case 2://Search and display an user
{
cout<<"Enter the first name of the client: ";
cin>>se_Fname[0];
cout<<endl;
cout<<"Enter the last name of the client: ";
cin>>se_Lname[0];
cout<<endl;
for (index = 1; index<= array_size; index++)
{
if (se_Fname[0] == Fname[index] && se_Lname[0] == Lname[index])
number = index;
}
cout<<"first name of the client: "<<Fname[number]<<"\nLast name of the client: "<<Lname[number];
cout<<"\nCar rented: ";
if (car[number] == 1)
{
cout<<"Toyota";
}
else
{
if (car[number] == 2)
{
cout<<"Jeep";
}
else
{
cout<<"BMW";
}
}
cout<<"\nMiles traveled: "<<miles[number]<<"\nDays rented: "<<rent[number];
cout<<"\nThe current debt is: $"<<deuda<<endl;
break;
}//end of case 2
case 3://Edit an user
{//start of case 3
cout<<"Enter the first name of the client: ";
cin>>se_Fname[0];
cout<<endl;
cout<<"Enter the last name of the client: ";
cin>>se_Lname[0];
cout<<endl;
for (index = 1; index<= array_size; index++)
{
if (se_Fname[0] == Fname[index] && se_Lname[0] == Lname[index])
number = index;
}
cout<<"Edit the days rented for "<<Fname[number]<<" "<<Lname[number]<<": ";
cin>>rent[number];
cout<<"Edit the miles traveled for "<<Fname[number]<<" "<<Lname[number]<<": ";
cin>>miles[number];
//Calculations
if (car[number] == 1)//Si es toyota
{
if (miles[number] < 100)
deuda = rent[number] * 26;
else
deuda = rent[number] * 26 + .18 * miles[number];
}
if (car[number] == 2)//Si es Jeep
{
if (miles[number] < 100)
deuda = rent[number]* 32;
else
deuda = rent[number] * 32 + .22 * miles[number];
}
if (car[number] == 3)//Si es BMW
{
if (miles[number] < 100)
deuda = rent[number] * 46;
else
deuda = rent[number] * 46 + .28 * miles[number];
}
break;
}//end of case 3
}//end of switch
cout<<"Continue running the program? Y/N: ";
cin>>flag;
}//end of while
system("pause");
return 0;
}
I made this program in visual c++. It supposed to be a program where the user choose an option and he creates some clients in order to see and edit a car rental place. Well for some reason the program keeps crashing and I don't even know what to do. I rewrote the program a couple of times but I don't know what I am doing wrong.
This is the error I get in Visual Studio 2010
http://i61.tinypic.com/23rtqae.png
I am using c++
//
#include "stdafx.h"
#include <iostream>
#include <string>
const int array_size = 10;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int car[array_size], client, index, menu, number, decision;
/*
car[] = 1 para Toyota, 2 para Jeep, 3 para BMW
client = cantidad de clientes
index= numero unico para saber quien es el cliente
menu = es las opciones del menu
number = despues de darle search y encontrar al usuario se usa ests variable para almacenar el index correcto
*/
float rent[array_size], miles[array_size], deuda;
/*
deuda = la deuda actual del cliente
miles[] = millas recorrida por el cliente
rent[] = dias que el cliente tiene el carro rentado
*/
char flag;//es para controlar y salir del loop
string Fname[array_size], Lname[array_size], se_Fname[array_size], se_Lname[array_size];
/*
Fname[] = nombre del cliente
Lname[] = apellido del cliente
se_Fname[] = el nombre a buscar
se_Lname[] = el apellido a buscar
*/
flag = 'y';
menu = 0;
while (flag == 'y' || flag == 'Y')
{
cout<<"*******************************************"<<endl<<"Enter a number to choose an option:\n"<<"1: Create an user\n"<<"2:Search and display an user data\n";
cout<<"3:Edit an already created user.\n*******************************************";
cin>>menu;//El menu del programa
switch(menu)
{//start of switch
case 1://Creates an user
{
cout<<"How many clients do you want to enter? ";
cin>>client;//number of clients to add in the array
cout<<endl;
for (index =1; index <= array_size; index++)
if (client > 0)
{
if (car[index] < 0)
{//Los datos a crearse de la tabla si el cliente no existe
cout<<"Enter the first name of the client ";
cin>> Fname[index];//El usuario entra el primer nombre del cliente
cout<<"\nEnter the last name of the client ";
cin>>Lname[index];//EL usuario entra el apellido
cout<<"\n**********\nEnter the car model to be rented; Enter a number to choose an option.\n1: 1: Toyota\n2: Jeep\n3:BMW\n**********\n";
cin>>car[index];//el usuario entra el modelo de carro a escoger
miles [index] = 0;//Las millas recorridas; es cero porque el cliente no ha recorrido millas
rent [index] = 0;//Es los dias que el cliente ha tenido el carro; es cero porque el cliente abrio la cuenta hoy
deuda = 0;//Es la deuda existente; es cero porque el cliente no tiene deuda
cout<<endl;
}
else
{
Fname [index] = "0";
Lname [index] = "0";
car [index] = 0;
miles [index] = 0;
rent [index] = 0;
deuda = 0;
}
client--;}
break;
}//end of case 1
case 2://Search and display an user
{
cout<<"Enter the first name of the client: ";
cin>>se_Fname[0];
cout<<endl;
cout<<"Enter the last name of the client: ";
cin>>se_Lname[0];
cout<<endl;
for (index = 1; index<= array_size; index++)
{
if (se_Fname[0] == Fname[index] && se_Lname[0] == Lname[index])
number = index;
}
cout<<"first name of the client: "<<Fname[number]<<"\nLast name of the client: "<<Lname[number];
cout<<"\nCar rented: ";
if (car[number] == 1)
{
cout<<"Toyota";
}
else
{
if (car[number] == 2)
{
cout<<"Jeep";
}
else
{
cout<<"BMW";
}
}
cout<<"\nMiles traveled: "<<miles[number]<<"\nDays rented: "<<rent[number];
cout<<"\nThe current debt is: $"<<deuda<<endl;
break;
}//end of case 2
case 3://Edit an user
{//start of case 3
cout<<"Enter the first name of the client: ";
cin>>se_Fname[0];
cout<<endl;
cout<<"Enter the last name of the client: ";
cin>>se_Lname[0];
cout<<endl;
for (index = 1; index<= array_size; index++)
{
if (se_Fname[0] == Fname[index] && se_Lname[0] == Lname[index])
number = index;
}
cout<<"Edit the days rented for "<<Fname[number]<<" "<<Lname[number]<<": ";
cin>>rent[number];
cout<<"Edit the miles traveled for "<<Fname[number]<<" "<<Lname[number]<<": ";
cin>>miles[number];
//Calculations
if (car[number] == 1)//Si es toyota
{
if (miles[number] < 100)
deuda = rent[number] * 26;
else
deuda = rent[number] * 26 + .18 * miles[number];
}
if (car[number] == 2)//Si es Jeep
{
if (miles[number] < 100)
deuda = rent[number]* 32;
else
deuda = rent[number] * 32 + .22 * miles[number];
}
if (car[number] == 3)//Si es BMW
{
if (miles[number] < 100)
deuda = rent[number] * 46;
else
deuda = rent[number] * 46 + .28 * miles[number];
}
break;
}//end of case 3
}//end of switch
cout<<"Continue running the program? Y/N: ";
cin>>flag;
}//end of while
system("pause");
return 0;
}
I made this program in visual c++. It supposed to be a program where the user choose an option and he creates some clients in order to see and edit a car rental place. Well for some reason the program keeps crashing and I don't even know what to do. I rewrote the program a couple of times but I don't know what I am doing wrong.
This is the error I get in Visual Studio 2010
http://i61.tinypic.com/23rtqae.png
I am using c++