c 2b 2b void to avoid functions

Solutions on MaxInterview for c 2b 2b void to avoid functions by the best coders in the world

showing results for - "c 2b 2b void to avoid functions"
Sara
06 Feb 2020
1/*The following example collects user data and formats it using seperate void
2statements */
3#include <iostream>
4#include <string>
5#include <stdio.h>
6#include <stdlib.h>
7
8using namespace std;
9
10// function declarations
11void inputData();
12void displayData();
13
14string name, addr1, addr2, postalCode;
15// the main method1
16int main()
17{
18    inputData();
19    displayData();
20
21    return 0;
22}
23
24// the first function definition
25void inputData()
26{
27    cout << "Kindly provide your address details \n"
28         << "Name: ";
29    getline(cin, name);
30    cout << "Address1: ";
31    getline(cin, addr1);
32    cout << "Address2: ";
33    getline(cin, addr2);
34    cout << "PostalCode: ";
35    getline(cin, postalCode);
36}
37
38// the second function definition
39void displayData()
40{
41    //system("cls"); exists for DOS or cmd windows
42    system("cls"); //system("clear") for Linux or MacOS
43    cout << name
44         << "\n"
45         << addr1
46         << "\n"
47         << addr2
48         << "\n"
49         << postalCode << endl;
50}