newgurl 0 Light Poster

In this section:

void readId (int& i,int& id, int MAX_SIZE, int& count)
{
     id [MAX_SIZE]; ****
     count = 0;
 do {
      
     cin>>id[i];
     }
     while (count<MAX_SIZE);

It gives error 45 invalid types `int[int]' for array subscript at ******

In this code :

void readNameAddress (int& MAX_LINE, int& MAX_SIZE, string& name, string& address, string & line, string& inputString,int& count, int& position);
{
    
    name [MAX_SIZE]; **************
    address [MAX_SIZE];
    line;
    count =0;
    
    do {
        getline(cin, line);   
        int position = line.find (',');
        name[count] = line.substr (0, position);
        address[count] = line.substr (position+1, MAX_LINE);
        count++;
        }
        while (count<MAX_SIZE);
        
        for (int i=0; i<count; i++)
        cout <<name[i]<<"\t"<<address[i]<<endl;
                      
}

it gives error 56 `name' undeclared (first use this function) at *********

I'll leave it at that for starters...

newgurl 0 Light Poster

Hope people dont mind (Lerner and iamthwee), but I would like to start a new post for this assignment of mine. since I think the length of the other one is putting people off and the code is now a lot different.

Can someone help me finalise this (has been going on for DAYS). There are only a few errors I believe.

I need to read (via piping) a txt file which has format:

3435344 @ L Brooks,12 Shaftsbury Road,Burwood NSW 2134
3435344 A 2005/02/22/08:22:41
3435344 A 2005/03/20/08:22:41
3435344 B 2005/03/23/18:22:41
3435344 B 2005/04/10/28:22:41
3435344 C 2005/03/11/08:22:41
3435344 C 2005/05/10/14:22:41
3435344 C 2005/05/19/06:22:43
3435344 D 2005/05/01/01:26:41
3873242 @ N McGoldrick,8 Colless Place,South Melbourne VIC 3205
3873242 B 2005/03/29/02:40:59
3873242 B 2005/05/16/02:40:59
3873242 C 2005/04/07/22:40:59
etc....

use, the cost of stations as A is $2.80, B is $ 2.30 etccc.

to print an invoice with totals per ID. (So one pages has total for ID 3435344, then totals for 3873242....)

This is the code I have prepared to date:

#include <iostream>
#include <string.h>
using namespace std;

void printGenericHeading(int&, int&);
void printCustomerHeading(int&, int&);
void readId (int& , int& , int& ,int&, int& );
void readNameAddress (int& , int& , string& , string& , string & , string& ,int& , int& );
void readDateTime (int& , int& , string& , string& , string& ,int& , int& );
void calculateTotalStation (string& , int , …
newgurl 0 Light Poster

You asked if I had abandoned the idea of using parallel arrays.

I havent. I just am walking in the dark here and only getting to understand the whole concept of parallel arrays.

I hope this final version is pretty close to how it should be, since I have to hand it in tonight (Australia time). but I also have to 'clean up' my hierarchy chart, PSEUDOCODE, and do a deskcheck chart, once I am happy the program is as close as I can get it).

Thanks for your time.
So am I almost there?

newgurl 0 Light Poster

I really want to print out total for id xx is $....
Total for id YY is $....

I have amended code.
Is this looking closer to it?
I have made comments where I get errors. My declarations here and there are weird now...

#include <iostream>
#include <string.h>
using namespace std;

void printGenericHeading(int&, int&);
void printCustomerHeading(int&, int&);
void readDateTime (int& , int& , string& , string& , string& ,int& , int& );
void calculateTotalStation (int& , char& , int& , double& , double& , double& , double& );
void resetControlTotals(double&);
void printTotalInvoice (int& , char& , double& , double& , double& , double& , double& );

const int MAX_DETAIL_LINES =100;
const int MAX_LINE = 100;
const int MAX_SIZE = 20;
double TotalInvoice = 0;
int pageCount = 0;
int lineCount = 0;
bool more= true;

void printGenericHeading(int& pageCount, int& lineCount)
{
     pageCount = pageCount +1;
     cout<<"INVOICE FOR TOLL EXPENSES"<<endl;
     cout<<"_________________________"<<endl;
     cout<<"TAG\tCUSTOMER\tSTATION"
     <<"\t\t\t\t\n";
     cout<<"ID\tNAME\t\tID\n";
     
     lineCount = 4;
     }
     
void printCustomerHeading(int& pageCount, int& lineCount)
{
     pageCount = pageCount +1;
     cout<<"\t\t\t\t\n";
     cout<<"t\t\t\t\tDATE\t\tTIME\tAMOUNT\n\n";
     
     lineCount = 3;
     }

void readDateTime (int& MAX_LINE, int& MAX_SIZE, string * date, string * time, string& inputString,int& count, int& position)
{
    
    date [MAX_SIZE];
    time [MAX_SIZE];
    inputString;
    count =0;
    
    do {
        cerr<<"processing..."<<endl;
        getline(cin, inputString);   
        if(cin.fail()) break;  
        
        int position = inputString.find ('/');
        date [count] = inputString.substr(0, 10); // this line gave error so I change string & to string * date)
        time [count]= inputString.substr(11,16-11); //this line gave error so I change string & to string * time) …
newgurl 0 Light Poster

So my method wont work at all? That is a shame coz it seems so nice and logical to me. I'll start making changes....

newgurl 0 Light Poster

Lerner,
If I make changes to make station[count], then will it be ok to have code like this for that section:


void calculateTotalStation (int& MAX_SIZE, string& station, int& count, double& totalA, double& totalB, double& totalC, double& totalD)
  
  {  
    count = 0;
    station [count];
    totalA = 0;
    totalB = 0;
    totalC = 0;
    totalD = 0;
    
   do{
      
       if (station [count] == 'A')
   {               
                   totalA= totalA + 2.20;
                   cout<<totalA;
              }
newgurl 0 Light Poster

By the way, as per iamthwee, I changed the station declaration to be string type. (just now). Sorry its not included above and I'll avoid resubmitting to avoid clutter.

newgurl 0 Light Poster

Geez,
thanks everyone.
I have been busy and come up with this. about 5 lines give me errors. So I have not been able to test the thing yet on the data. But I am excited about getting closer!

I have also worked on my indentations. Please check it out.

#include <iostream>
#include <string.h>
using namespace std;

void printGenericHeading(int&, int&);
void printCustomerHeading(int&, int&);
void readDateTime (int& , int& , string& , string& , string& ,int& , int& );
void calculateTotalStation (int& , char& , int& , double& , double& , double& , double& );
void resetControlTotals(double&);
void printTotalInvoice (int& , char& , double& , double& , double& , double& , double& );

const int MAX_DETAIL_LINES =100;
const int MAX_LINE = 100;
const int MAX_SIZE = 20;
double TotalInvoice = 0;
int pageCount = 0;
int lineCount = 0;
bool more= true;

void printGenericHeading(int& pageCount, int& lineCount)
{
     pageCount = pageCount +1;
     cout<<"INVOICE FOR TOLL EXPENSES"<<endl;
     cout<<"_________________________"<<endl;
     cout<<"TAG\tCUSTOMER\tSTATION"
     <<"\t\t\t\t\n";
     cout<<"ID\tNAME\t\tID\n";
     
     lineCount = 4;
     }
     
void printCustomerHeading(int& pageCount, int& lineCount)
{
     pageCount = pageCount +1;
     cout<<"\t\t\t\t\n";
     cout<<"t\t\t\t\tDATE\t\tTIME\tAMOUNT\n\n";
     
     lineCount = 3;
     }

void readDateTime (int& MAX_LINE, int& MAX_SIZE, string& date, string& time, string& inputString,int& count, int& position)
{
    
    date [MAX_SIZE];
    time [MAX_SIZE];
    inputString;
    count =0;
    
    do {
        cerr<<"processing..."<<endl;
        getline(cin, inputString);   
        if(cin.fail()) break;  
        
        int position = inputString.find ('/');
        date [count] = inputString.substr(0, 10); 
        time [count]= inputString.substr(11,16-11);
        count++;
        }
        while (count<MAX_SIZE);
        
        for (int i=0; i<count; i++)
        cout <<date[i]<<"\t"<<time[i]<<endl;
                      
  }   
  void calculateTotalStation (int& MAX_SIZE, char& station, int& count, double& totalA, double& totalB, …
newgurl 0 Light Poster

Can someone suggest why this for loop is not working as it should?

#include <iostream>
#include <string>
using namespace std;

int main ()
{   

    const int MAX_SIZE=5;
    char station [MAX_SIZE];
      
    int count = 0;
   
   do{
      cout<<"Enter station:"<<endl;
      cin>>station[count];
      double totalA = 0;
       if (station [MAX_SIZE] = 'A')
   {               
              for (int i=0; i<count; i++)
              totalA= totalA + 2.20;
              cout<<totalA;
              }
              }
   while (count<MAX_SIZE); 
              
              
                     system ("pause");
        return 0;
               }

it returns a value of 0 everytime.

newgurl 0 Light Poster

Shame I cant delete old posts, because I have improved my code.

Please ignore the last 2 codes.

I will update soon.

newgurl 0 Light Poster

or just [ at the start and ] at the end?

newgurl 0 Light Poster

I'm sorry about that. I actually dont understand it fully.
I thought I did it, but obviously not.
Do I have to put a [] around everyline then?

newgurl 0 Light Poster

OK,

This one is giving me the error:
16 "incompatible types in assignment of `std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to `std::string[100]' "

It look like it wants me to remove reference to MAX_LINE from string date declaration....but dont I need that to store into array?

Also, with the substring numbers, have I set them out right for this inputString:

3435344 A 2005/02/22/08:22:41


[

#include <iostream>
#include <string>
using namespace std;

int main ()
{
    
    const int MAX_LINE = 100;
    string date [MAX_LINE];
    string time [MAX_LINE];
    string inputString;
    int count =0;
   
    do {
        int position = inputString.find ('/');
        date = inputString.substr(0, 4); 
        time = inputString.substr(7,15-4);
        }
        while (count<MAX_LINE);
        
        for (int i=0; i<count; i++)
        cout <<date[i]<<"/t"<<time[i]<<endl;
        
        system ("pause");
        return 0;
               }

]

newgurl 0 Light Poster

OK,
I've written this small section of code, as per last suggestion:

#include <iostream>
#include <string>
using namespace std;

int main ()
{
    
    const int MAX_LINE = 100;
    string name [MAX_LINE];
    string address [MAX_LINE];
    string line;
    int count =0;
   
    do {
        int position = line.find (',');
        string name = line.substr (0, position);
        string address = line.substr (position, MAX_LINE);
        }
        while (count<MAX_LINE);
        
        for (int i=0; i<count; i++)
        cout <<name[i]<<"/t"<<address[i]<<endl;
        
        system ("pause");
        return 0;
               }

It looks good to me, but it wont run. I think it goes in a loop or something because my program makes the .cpp crash out.

Can you suggest further on this? I will now go and do a program for storing the date and time as well.

APPRECIATE YOUR HELP BY THE WAY!

newgurl 0 Light Poster

We havent studied classes yet. I was trying to figure out how to use substr and get.line to store strings into parallel arrays. (I know this in theory but cant find HOW to do it). So, I would like to find character '@', anything after that is the Name, Address.
Then anything that is not '@' (ie will be a station ID such as A, B, C...), anything after that will be my date and time).
IN THEORY. Again, I dont know the code. If someone could kindly tell me how substr is organised or how I get a string and store it into an array, that's what I was invisaging. Of-course open to other recommendations.

(I am nervous I wont finish this by Friday).
Renee

newgurl 0 Light Poster

Thanks for your help. I will begin working with this.
However, as stated previously I also have problem on how to insert those string into arrays.
The above code I wrote, only enters single values. I need to make parallel arrays, so can someone guide me with how a string is passed into an array?

if item equals @
input into name and address //this shouldnt be too hard for me but...
else
store item in container if desired
input into date and time string //...how do I store the date and time?

THANKS.

newgurl 0 Light Poster

By the way, I have used this code so far to read first line (ID, station, Nameand Address):

void readRecord (int& id, string& name, int& item, double& cost, int& qty, bool& more)
{
      //int id;
      char station;
      string rest;
      while(true) {
                  cerr << "reading data and processing to file...";        
                  cin >> id;
                  if(cin.fail()) break;  
                  cin >> station;
                  if(cin.fail()) break;
                  cin >> ws;            
                  getline(cin, rest);    
                  if(cin.fail()) break;
                  
  }
newgurl 0 Light Poster

Hello,
I am stuck on an assignment I am working on. To be honest, the way I've structured it, it goes a bit beyond me.

Can someone kindly assist?

I have to get the following text:

3435344 @ L Brooks,12 Shaftsbury Road,Burwood NSW 2134
3435344 A 2005/02/22/08:22:41
3435344 A 2005/03/20/08:22:41
3435344 B 2005/03/23/18:22:41
3435344 B 2005/04/10/28:22:41
3435344 C 2005/03/11/08:22:41
3435344 C 2005/05/10/14:22:41
3435344 C 2005/05/19/06:22:43
3435344 D 2005/05/01/01:26:41
3873242 @ N McGoldrick,8 Colless Place,South Melbourne VIC 3205
3873242 B 2005/03/29/02:40:59
3873242 B 2005/05/16/02:40:59
3873242 C 2005/04/07/22:40:59
3873242 D 2005/03/02/02:40:59


...
pipe it to a program that sorts the stations, date time, then outputs an invoice with total amount owing. (I have been told Station A costs 2.20, B costs 2.80 etc...)

I am in first year, first semester. So I have to use easy methods.

I have made functions which basically: initialise, printHeadings (such as customer name and ID), readRecords (id, date, time, station), process Record (get station, times quantity of times entered by relevant charge), printInvoice (total for each station, then total for invoice).

My first problem:
How do I read from this file data to store into arrays, the two separate types of line (ie one has address, other has station, date and time). Do I do this within the one function or split it up into 2 functions? (One line I will use for just typing up customer details, the other I will use further to calculate amount to invoice....

Thanks for your time.

newgurl 0 Light Poster

Thanks for your time Dave.
I will comment out any "extra" stuff next time.

newgurl 0 Light Poster

Hello,
I am new at this. I am trying to work with calling functions here. (Eventually I want to do some simple calcs on cost of going through a station...)but am getting an error on line marked with *****
initialise line within main int(). Can someone kindly suggest why it gives me error: "invalid initialisation of reference of type 'double&' from expression of type 'float'. (I have checked that all my function floats and doubles match up correctly)....

Thanks in advance for your help.

#include <iostream>
#include <string.h>
using namespace std;

void initialise(float&, double& ,int& ,int& ,bool&);
void printPageHeadings(int&, int&);
void readRecord (int&, string& , int&, float&, int&, bool&);
void printControlCost(string, float& , int& );
void processRecord(int ,string ,int,float,int ,float& ,float&,int);
void printDetailLine (int ,string ,int ,float ,int ,float , int&);
void resetControlTotals(float&);
void accumulateTotals(float , float&, float& );

const int MAX_DETAIL_LINES =100;
void initialise(float& controlTotal,double& invoiceTotal,int& pageCount,int& lineCount,bool& more)
{
controlTotal = 0;
invoiceTotal = 0;
pageCount = 0;
lineCount = 0;
more= true;
}

void printPageHeadings(int& pageCount, int& lineCount)
{
     pageCount = pageCount +1;
     cout<<"TAG\tPERSON'S\tSTATION"
     <<"\t\t\t\t\n";
     cout<<"ID\tNAME\t\tID\t\tCOST\t\QTY\tAMOUNT\n\n";
     
     lineCount = 4;
     }
     
void readRecord (int& id, string& name, int& item, float& cost, int& qty, bool& more)
{
     cerr<<"-->";
     cin>>id>>name;
     cin>>item>>cost>>qty;
     more =! cin.fail() && id;
     //validateName(name);
     }
     
//void validateName(string name)
//{
  //   static string pad= "     ";
    // name = name + pad + pad +pad;
     //name= name.substr(0,3*TABWIDTH-1);
     //}
     
void printControlCost(string prevName, float& controlTotal, int& lineCount)
{
     cout<<"\t\tTotal Cost for "<<prevName;
     cout<<"\t$"<<controlTotal<<"\n\n";
     lineCount = lineCount …
newgurl 0 Light Poster

Although it wont make it bold, I just realised it still uses it. So library is called after all. Sorry to waste anyone's time.

newgurl 0 Light Poster

Hello,
Can you please assist, why my Dev C++ program, wont see that I am trying to introduce the string library? Eaxmple:

#include <iostream>
#include <string.h>
using namespace std;
...
...
...
int id;
    string name;
    int item;
    float cost;

int is bold, float is bold, but string is not...
Can someone give me an idea why?

I also tried <string.h> .

Thanks for your assistance!

newgurl 0 Light Poster

Let me know if you want me to post what I wrote in case you think I changed your stuff....

newgurl 0 Light Poster

To sort three numbers without arrays or loops is quite funny...

I think the best sudo code is as follows:

PROGRAM  Order
   IMPLICIT  NONE

   INTEGER  :: a, b, c

   READ(*,*)  a, b, c

   IF (a < b) THEN                 ! a < b here
      IF (a < c) THEN              !   a < c     : a the smallest
         IF (b < c) THEN           !      b < c  : a < b < c
            WRITE(*,*)  a, b, c
         ELSE                      !      c <= b : a < c <= b
            WRITE(*,*)  a, c, b
         END IF
      ELSE                         !   a >= c    : c <= a < b
         WRITE(*,*) c, a, b
      END IF
   ELSE                            ! b <= a here
      IF (b < c) THEN              !   b < c     : b the smallest
         IF (a < c) THEN           !     a < c   : b <= a < c
            WRITE(*,*)  b, a, c
         ELSE                      !     a >= c  : b < c <= a
            WRITE(*,*)  b, c, a
         END IF
      ELSE                         !   c <= b    : c <= b <= a
         WRITE(*,*)  c, b, a
      END IF
   END IF

END PROGRAM  Order

If you can use loops have a look at hackwizz's solution

[edit] Actually hackwizz's code is probably not the best to look at. Ha ha it's awful[/edit]
[IMG]http://img476.imageshack.us/img476/5171/cut20ln.png[/IMG]
Piworld ™
[Tis simple as Pie]

HEY,
just tried that.

BAD NEWS.
Order is no good:

Here is the output for 2 trials (one worked ok)

This …

newgurl 0 Light Poster

Why don't you sort them using a sorting Al-Gore-it-him.

So put the words inside an array or vector first?

[IMG]http://img476.imageshack.us/img476/5171/cut20ln.png[/IMG]
Piworld ™
[Tis simple as Pie]

Hmmm, havent covered arrays yet... so basically trying to do this in really simplistic methods...

newgurl 0 Light Poster

show ur input and output ..or exactly the error..

OK,
here are 2 examples, one is good, other not so good...
ATTEMPT1

This program will ask you to enter 3 words.
It will then diplay them in order of word length
(Shortest word first)
Please enter 3 words
wrrrrr
wrrr
wrrrr
The order of words from smallest to largest is wrrr and wrrrr and wrrrrr
Press any key to continue . . .

ATTEMPT2

This program will ask you to enter 3 words.
It will then diplay them in order of word length
(Shortest word first)
Please enter 3 words
wr
wrrr
wrrrrr
The order of words from smallest to largest is wr and wrrrrr and wrrr
Press any key to continue . . .

newgurl 0 Light Poster

What error is coming...some logical error might be?? does it happen that it is being printed in the dictionary order??

Hello,
thanks for reply, but no, doesnt seem to be dictionary related.
I just try dork words like wrr and wrrrrrr and wr, and just get it to compare and try to organise by length of string.

newgurl 0 Light Poster

I am trying with this method. (you are the second person who has suggested- so I'b better try)...

But no, still weird error of putting them in varying orders....

#include <iostream>
#include <string.h>


using namespace std;


int main ()
{
int ref,x,y,z;
char word1[50] = "word1 string";
char word2[50] = "word2 string";
char word3[50] = "word3 string";


string wordsml;
string wordmed;
string wordlge;


cout<<"This program will ask you to enter 3 words. \n"
"It will then diplay them in order of word length \n"
"(Shortest word first)"<<endl;



cout<<"\tPlease enter 3 words\n";
cin>>word1>>word2>>word3;


x=strlen (word1);
y=strlen (word2);
z=strlen (word2);


if (x<y)
{
wordsml = word1;
wordlge = word2;
}


if (x>y)
{
wordsml =word2;
wordlge = word1;
}


ref=strlen(wordlge.c_str());


if (ref<z)
{
wordmed = wordlge;
wordlge = word3;
}


if (ref>z);
wordmed = word3;


cout<<"The order of words from smallest to largest is "<<wordsml<<" and "<<wordmed<<" and "<<wordlge<<endl;


system("pause");
return 0;


}
newgurl 0 Light Poster

hello,
Thanks to previous help which has gotten me this far.
However, my lovely program, although looks great in theory doesnt do what its supposed to do. When I type in 3 words, it doesnt put them in order as it should. Can someone point out to me where I am going wrong?

#include <iostream>
#include <string.h>


using namespace std;


int main ()
{
char word1[50] = "word1 string";
char word2[50] = "word2 string";
char word3[50] = "word3 string";


string wordsml;
string wordmed;
string wordlge;


cout<<"This program will ask you to enter 3 words. \n"
"It will then diplay them in order of word length \n"
"(Shortest word first)"<<endl;



cout<<"\tPlease enter 3 words\n";
cin>>word1>>word2>>word3;


if (strcmp (word1, word2)< 0)
{
wordsml = word1;
wordlge = word2;
}


if (strcmp (word1, word2)> 0)
{
wordsml =word2;
wordlge = word1;
}



if (strcmp(wordlge.c_str(), word3) <0);
{
wordmed = wordlge;
wordlge = word3;
}


if (strcmp(wordlge.c_str(), word3) >0);
wordmed = word3;


cout<<"The order of words from smallest to largest is "<<wordsml<<" and "<<wordmed<<" and "<<wordlge<<endl;


system("pause");
return 0;


}
newgurl 0 Light Poster

Hello,
I am one of those new assignment people, BUT I have tried to resolve this for a while now. Cant find much on google or other C++ sites.

I am trying to compare string lengths of 3 words and then display them in order of length.

My code is (I get stuck just before my first if statement):

#include <iostream>
#include <string.h>

using namespace std;

int main ()
{
int x,y,z;
string word1 = "word1 string";
string word2 = "word2 string";
string word3 = "word3 string";


cout<<"Please enter 3 words/n";
cin>>word1>>word2>>word3;

x = strcmp(word1, word2); ***THIS LINE IS THE PROBLEM***
{

if (strcmp (word1, word2)< 0)
wordA = word1
wordB = word2
}
if (strcmp (word1, word2) > 0)
{
wordA =word2
wordB =word1
}

y = strcmp (wordA, word3)
if (y < 0)
wordsml = wordA

z = strcmp (wordB, word3)
if (z < 0)
wordm = wordB

if (z > 0)
wordlge = word3

cout<<"The order of words from smallest to largest is "<<word sml<<" and "<<wordm<<" and "<<wordlge<,endl;

system("pause");
return 0

}

I know I have done something wrong in my setout, but the explanation given to me is not very clear to me and I dont know how to resolve : ******no matching function for …