Autograde Fail?

I'm currently using an online (chegg) copy of Cay Horstmann's Big C++ Late Objects 3rd edition. I'm on chapter 7 trying to work out one of the examples on structures, and I came across something peculiar. This code seems to present with the expected output, but for some reason the autograder keeps failing me on it. Is there actually something wrong with this code or can I blame it on the textbook?

Here's the worked text field it allows me to edit with the (I completed the code inside the void()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
using namespace std;

struct StreetAddress
{
   int house_number;
   string street_name;
};

void print_address(StreetAddress address, bool number_first)   
{
   if(number_first)
   {
     cout << address.house_number << " " << address.street_name << endl; 
   }
   else 
   {
      cout << address.street_name << " " << address.house_number << endl;
   }
   
}


And here's the tester .cpp
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
#include <iostream>
#include <string>
using namespace std;

struct StreetAddress
{
   int house_number;
   string street_name;
};

void print_address(StreetAddress address, bool number_first);

int main()
{
   StreetAddress white_house;
   white_house.house_number = 1600;
   white_house.street_name = "Pennsylvania Avenue";
   print_address(white_house, true);
   cout << endl << "Expected: 1600 Pennsylvania Avenue" << endl;
   StreetAddress train_station;
   train_station.house_number = 1;
   train_station.street_name = "Bahnhofstraße";
   print_address(train_station, false);
   cout << endl << "Expected: Bahnhofstraße 1" << endl;
   return 0;
}


The output from the autograder is:

Running Tester.cpp

fail fail
1600 Pennsylvania Avenue

Expected: 1600 Pennsylvania Avenue
Bahnhofstraße 1

Expected: Bahnhofstraße 1
Score

0/2
Last edited on
Out of curiosity. what happens if you omit the << endl from your print_address() implementation? I see the following lines have a newline at the start of their output so it should still display OK.

Andy
Last edited on
Yep, it was the extraneous << endl on the end of each line. Thanks!
Topic archived. No new replies allowed.