1

So recently I have been developing a program that asks the user some questions and asks for their reply, it then stores it to an array, and writes it out to an output file, although I don't get the information the user inputs but this code thing: 0x4080c0. Can someone please help me, here is my code as well:

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

string q1 = "Distance Flown:";
string q2 = "Total Fuel Used:";
string q3 = "Total Flight Time:";
string q4 = "Number Of Passengers:";
string q5 = "Total Profit:";
string q6 = "Any futher comments goes here:";

string logAwensers[6];

int main()
{
cout << "Please enter your pilot log here."<< endl;
cout << q1 << endl;
getline(cin, logAwensers[0]);
cout << q2 << endl;
getline(cin, logAwensers[1]);
cout << q3 << endl;
getline(cin, logAwensers[2]);
cout << q4 << endl;
getline(cin, logAwensers[3]);
cout << q5 << endl;
getline(cin, logAwensers[4]);
cout << q6 << endl;
getline(cin, logAwensers[5]);

cout << logAwensers << endl;
ofstream writer("PilotLog.txt", ios::app);

if(! writer)
{
    cout << "Error writing file" << endl;
}

    return -1;
}
writer << logAwensers << endl;
writer.close();
return 0;
}

Thanks.

Skywalker
  • 1,590
  • 1
  • 18
  • 36
James Pac
  • 31
  • 5
  • You should indent your code properly. The `}` after `return -1;` is closing main function. And please, don't use global variables. – O'Neil Jan 10 '18 at 03:24
  • Oh okay sorry, I forgot to mention i'm new to programming. – James Pac Jan 10 '18 at 03:26
  • And, you are currently writting the address of the array. Use a for loop, or write each element one by one. (No need to mention, it's obvious ;)) – O'Neil Jan 10 '18 at 03:26
  • Unrelated to your question, but probably good fundamental business to learn/gain awareness of: [Why is “using namespace std” considered bad practice?](https://stackoverflow.com/q/1452721/6610379) – Phil Brubaker Jan 10 '18 at 04:17

1 Answers1

3

Instead of:

cout << logAwensers << endl;

Try something like:

for (const auto &a : logAwensers)
{
    cout << a << endl;
}
Sid S
  • 6,037
  • 2
  • 18
  • 24