Inputting multiple lines and outputting them together

I'm having trouble with my output. The output is correct, but it outputs each line seperately and I can't figure out how to have each line input as many times as the user wants, until "QUIT" is entered, and then output each line at the end.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main ()
{
   string latin;

   string ae = "ae";
   string arum = "arum";
   string is = "is";
   string am = "am";
   string as = "as";
   string orum = "orum";
   string um = "um";
   string os = "os";
   string a = "a";
   string i = "i";
   string o = "o";
 
   while (latin != "QUIT")
   {
      getline(cin, latin); 

      string nominative = latin.substr(0, (latin.find(' ', 0)));

      string genitive = latin.substr(latin.find(" ") + 1); 
      genitive = genitive.substr(0, genitive.length()); 

      if (genitive.substr((genitive.length()-2), 2) == "ae")
      {
         cout << "Nom     " << left << setw(8) << nominative << left << setw(8) << genitive.replace((genitive.length()-2), 2, ae) << endl;
         cout << "Gen     " << left << setw(8) << genitive.replace((genitive.length()-2), 2, ae) << left << setw(8) << genitive.replace((genitive.length()-2), 2, arum) << endl;
         cout << "Dat     " << left << setw(8) << genitive.replace((genitive.length()-4), 4, ae) << left << setw(8) << genitive.replace((genitive.length()-2), 2, is) << endl;
         cout << "Acc     " << left << setw(8) << genitive.replace((genitive.length()-2), 2, am) << left << setw(8) << genitive.replace((genitive.length()-2), 2, as) << endl;
         cout << "Abl     " << left << setw(8) << genitive.replace((genitive.length()-2), 2, a) << left << setw(8) << genitive.replace((genitive.length()-1), 1, is) << endl;
      }        

      else if (genitive.substr((genitive.length()-1), 1) == "i") 
      {
         if ((nominative.substr((nominative.length()-2), 2) == "us") || (nominative.substr((nominative.length()-1), 1) == "r")) 
         {
            cout << "Nom     " << left << setw(8) << nominative << left << setw(8) << genitive.replace((genitive.length()-1), 1, i) << endl;
            cout << "Gen     " << left << setw(8) << genitive.replace((genitive.length()-1), 1, i) << left << setw(8) << genitive.replace((genitive.length()-1), 1, orum) << endl;
            cout << "Dat     " << left << setw(8) << genitive.replace((genitive.length()-4), 4, o) << left << setw(8) << genitive.replace((genitive.length()-1), 1, is) << endl;
            cout << "Acc     " << left << setw(8) << genitive.replace((genitive.length()-2), 2, um) << left << setw(8) << genitive.replace((genitive.length()-2), 2, os) << endl;
            cout << "Abl     " << left << setw(8) << genitive.replace((genitive.length()-2), 2, o) << left << setw(8) << genitive.replace((genitive.length()-1), 1, is) << endl;
         }
         
         else if (nominative.substr((nominative.length()-2), 2) == "um")
         {
            cout << "Nom     " << left << setw(8) << nominative << left << setw(8) << genitive.replace((genitive.length()-1), 1, a) << endl;
            cout << "Gen     " << left << setw(8) << genitive.replace((genitive.length()-1), 1, i) << left << setw(8) << genitive.replace((genitive.length()-1), 1, orum) << endl;
            cout << "Dat     " << left << setw(8) << genitive.replace((genitive.length()-4), 4, o) << left << setw(8) << genitive.replace((genitive.length()-1), 1, is) << endl;
            cout << "Acc     " << left << setw(8) << genitive.replace((genitive.length()-2), 2, um) << left << setw(8) << genitive.replace((genitive.length()-2), 2, a) << endl;
            cout << "Abl     " << left << setw(8) << genitive.replace((genitive.length()-1), 1, o) << left << setw(8) << genitive.replace((genitive.length()-1), 1, is) << endl;
         } 
      }
   }

   return 0;
}


The output looks like this:

dea deae
Nom     dea     deae    
Gen     deae    dearum  
Dat     deae    deis    
Acc     deam    deas    
Abl     dea     deis    
servus servi
Nom     servus  servi   
Gen     servi   servorum
Dat     servo   servis  
Acc     servum  servos  
Abl     servo   servis  
puer pueri
Nom     puer    pueri   
Gen     pueri   puerorum
Dat     puero   pueris  
Acc     puerum  pueros  
Abl     puero   pueris  
bellum belli
Nom     bellum  bella   
Gen     belli   bellorum
Dat     bello   bellis  
Acc     bellum  bella   
Abl     bello   bellis  
liber libri
Nom     liber   libri   
Gen     libri   librorum
Dat     libro   libris  
Acc     librum  libros  
Abl     libro   libris  
QUIT


When it should look like this:

Input

1
2
3
4
5
6
dea deae   
servus servi  
puer pueri  
bellum belli 
liber libri  
QUIT


Output

Nom     dea     deae
Gen     deae    dearum
Dat     deae    deis
Acc     deam    deas
Abl     dea     deis

Nom     servus  servi
Gen     servi   servorum
Dat     servo   servis
Acc     servum  servos
Abl     servo   servis

Nom     puer    pueri
Gen     pueri   puerorum
Dat     puero   pueris
Acc     puerum  pueros
Abl     puero   pueris

Nom     bellum  bella
Gen     belli   bellorum
Dat     bello   bellis
Acc     bellum  bella
Abl     bello   bellis
 
Nom     liber   libri
Gen     libri   librorum
Dat     libro   libris
Acc     librum  libros
Abl     libro   libris


Any help would be greatly appreciated. Thanks.
Last edited on
Not sure, but I think the first example of "output" you give is from an interactive terminal session?

i.e. the text 'dea deae' is typed by the user and the program replies with the following five lines?

If you want to batch process your input then you can enter it into a text file and have your program read from the text file (no program changes required!)

example

./latin_thing < input_file.txt

where latin_thing is your compiled program and input_file.txt is a text file of the input latin.

The command line < operator means 'read input from this'

Topic archived. No new replies allowed.