There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
C++ Storage of Strings


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Fury1671's Avatar
Junior Member with 1 posts.
 
Join Date: May 2005
11-May-2005, 07:08 PM #1
C++ Storage of Strings
I'm having a bit of trouble storing a 2d array of strings with C++. When I attempt to display the strings, I come up with no output. Below is what I get when I attempt to display those strings I entered. I think its how I'm storing the strings, but Im unsure at the moment how to.

Make:
Model:
Year:
and so on.

An example on what it should show:
Make: Ford
Model: Focus
Year: 1995
Color: Black
VIN: A5S179DAC5AC6G27Q
Buying Cost: $1500.00
Selling Cost: $2000.00


The program has to store different information on different cars and Add, Delete, Edit, or Display those records.
Any feedback would be very nice.

Code:
#include<iostream>
#include<string>

using namespace std;

struct Auto
{
	string VIN[18][11];
	string make[21][11];
	string model[21][11];
	string year[5][11];
	string color[21][11];
	string cost[9][11];
	string sell[9][11];
};

void menu();
int addRecord(int[]);
int editRecord(int[]);
int delRecord(int[]);
void dispRecord(int[]);


main()
{
  
	
	  menu();

       return 0;
}

void menu()
{
	int choice, recordInfo[10]={0,0,0,0,0,0,0,0,0,0};
	
	   
       do{
               cout<<"\n\t\tDeal 4-U Cars\n\n";
               cout<<"1.\tAdd a record.\n"
                       <<"2.\tEdit a record\n"
                       <<"3.\tDelete a record\n"
                       <<"4.\tDisplay record.\n"
                       <<"5.\tQuit the Program\n";
			   cout<<"Choose an option: ";
               cin>>choice;

               switch(choice)
               {
               case 1: addRecord(recordInfo);
                       break;
               /*
			   case 2: editRecord(recordInfo);
                       break;
               case 3: delRecord(recordInfo);
                       break;
               */
			   case 4: dispRecord(recordInfo);
                       break;
               case 5: cout<<"Thank you for using this program.\n";
                       break;
               default: cout<<"You did not enter a valid choice\n";
               }

       }while(choice != 5);
}

int addRecord(int recordInfo[])
{
    
	Auto info;	
	int count;   
	
	cout<<"In which inventory slot do you wish to store this information\n";
	cin>>count;

	if(recordInfo[count]==0)
	{
		cout<<"Please enter the make of the car: ";
		cin>>info.model[0][count];
		
		cout<<"Please enter the model of the car: ";
		cin>>info.model[0][count];
		
		cout<<"Please enter the year the car was made: ";
		cin>>info.year[0][count];

		cout<<"Please enter the color of the car: ";
		cin>>info.color[0][count];
		
		cout<<"Please enter the VIN number of the car: ";
		cin>>info.VIN[0][count];
		
		cout<<"Please enter the price the car was bought for: $";
		cin>>info.cost[0][count];
		
		cout<<"Please enter the selling price of the car: $";
		cin>>info.sell[0][count];

		recordInfo[count]=1;
	}

	else
	{
		cout<<"This record already has information.\n"
			<<"Please edit the information in this record or delete it\n";
	}

	return recordInfo[count];

}

/*int editRecord(int recordInfo[])
{
       
	Auto info;
	cout<<"Edit a record here\n";
	
	return recordInfo[];
}

int delRecord(int recordInfo[])
{
    Auto info;   
	
	cout<<"Delete a record here\n";

	return;
}*/

void dispRecord(int recordInfo[])
{
    Auto info;   
	int count;   
	
	cout<<"Which inventory slot do you want to display the information for?\n";
	cin>>count;

	if(recordInfo[count]==1)
	{
		cout<<"\nMake: "<<info.make[0][count];
		cout<<"\nModel: "<<info.model[0][count];
		cout<<"\nYear: "<<info.year[0][count];
		cout<<"\nColor: "<<info.color[0][count];
		cout<<"\nVIN: "<<info.VIN[0][count];
		cout<<"\nBuying Cost: $"<<info.cost[0][count];
		cout<<"\nSelling Price: $"<<info.sell[0][count];
		cout<<"\n\n";
	}

	else
		cout<<"That record is empty.\n\n";
}
Arcadion's Avatar
Computer Specs
Senior Member with 1,756 posts.
 
Join Date: Sep 2004
Location: Taupo, New Zealand
Experience: IT Professional
12-May-2005, 01:13 AM #2
If you want to use the string type, you should remove the first square bracket values (where you've defined the length of the string) from your struct definition. You only use that when creating an array of chars, a string's length doesn't need to be defined in this way. Remove the same part when you're getting your data with cin, and later on when you're displaying records with cout, also.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:05 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.