Answers for "c++ void to avoid functions"

C++
0

c++ void to avoid functions

/*The following example collects user data and formats it using seperate void
statements */
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

// function declarations
void inputData();
void displayData();

string name, addr1, addr2, postalCode;
// the main method1
int main()
{
    inputData();
    displayData();

    return 0;
}

// the first function definition
void inputData()
{
    cout << "Kindly provide your address details \n"
         << "Name: ";
    getline(cin, name);
    cout << "Address1: ";
    getline(cin, addr1);
    cout << "Address2: ";
    getline(cin, addr2);
    cout << "PostalCode: ";
    getline(cin, postalCode);
}

// the second function definition
void displayData()
{
    //system("cls"); exists for DOS or cmd windows
    system("cls"); //system("clear") for Linux or MacOS
    cout << name
         << "\n"
         << addr1
         << "\n"
         << addr2
         << "\n"
         << postalCode << endl;
}
Posted by: Guest on June-13-2021

Browse Popular Code Answers by Language