Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ structs

//
//  main.cpp
//  Structures
//

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

struct variables {
    
    string greeting = "Hello, ";
    string name;
    
    string question = "How old are you? 
";
    int age;
    
};

int main() {
    struct variables introduction;
    
    cout << "What is your name?" << endl;
    cin >> introduction.name;
    cout << introduction.greeting << introduction.name << "!" << endl;
    cout << introduction.question;
    cin >> introduction.age;
    cout << "You are " << introduction.age << " years old." << endl;
    
    return 0;
}

/*
 * example run:
 * What is your name?
 * Alex
 * Hello, Alex!
 * How old are you?
 * 30
 * You are 30 years old.
 */
Source by beginnersbook.com #
 
PREVIOUS NEXT
Tagged: #structs
ADD COMMENT
Topic
Name
3+9 =