Addresses in arrays.

Am working on a program where am attempting to do an array creation called block that has the ability of holding three addresses. My array should be able to ask the user for the three required addresses. Am interested in knowing if an enum class is required before the struct and array for the information to be pulled in the array and do the creation of the count and cin for the information address? Am actually unable to understand this. Below is what am able to do so far:

#include <iostream>
#include <string>
#include <array>


struct Block
{
int streetNumber;
std::string street;
std::string city;
std::string state;
int zipcode;

};


int main()
{
std::array<Block, 5> address{ };
{
Block.at(0);
Block.at(1);
Block.at(2);
Block.at(3);
Block.at(4);
}

return 0;

)

Here is my new code. The first address works fine, but after the requests for both addresses pops up at the same time and i can't input the information:

#include <iostream>
#include <string>
#include <array>


struct Address
{
int streetNumber{};
std::string street{};
std::string city{};
std::string state{};
int zipcode{};

};


int main()
{
std::array<Address, 5> address{ };
{
std::cout << "Enter your primary address: \n";
std::cin >> address.at(0).streetNumber >> address.at(1).street >> address.at(2).city >> address.at(3).state >> address.at(4).zipcode;


std::cout << "Enter your secondary address: \n";
std::cin>> address.at(0).streetNumber >> address.at(1).street >> address.at(2).city >> address.at(3).state >> address.at(4).zipcode;


std::cout << "Enter an alternative address: \n";
std::cin>> address.at(0).streetNumber >> address.at(1).street >> address.at(2).city >> address.at(3).state >> address.at(4).zipcode;

}

return 0;
}
https://www.theengineeringprojects.com/2019/11/introduction-to-interface-in-c-sharp.html
Last edited on
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
#include <iostream>
#include <string>
#include <array>

struct Block
{
    int streetNumber = 0 ;
    std::string street;
    std::string city;
    std::string state;
    int zipcode = 0 ;
};

Block get_block() // read in an address entered by the user
{
    Block blk ;
    std::cin >> blk.streetNumber >> blk.street >> blk.city >> blk.state >> blk.zipcode ;
    return blk ;
}

int main ()
{
    std::array< Block, 3 > addresses ; // three addresses

    std::cout << "Enter your primary address: \n";
    addresses[0] = get_block() ;

    std::cout << "Enter your secondary address: \n";
    addresses[1] = get_block() ;

    std::cout << "Enter your alternate address: \n";
    addresses[2] = get_block() ;

    // ...
}
Topic archived. No new replies allowed.