[CPP, C++] Arrays and Multi-Dimension Arrays, enum, constant variable


// ConsoleApplication3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

//three global integers
int FirstNumber = 0 ;
int SecondNumber = 0 ;
int MultiplicationResult = 0 ;


void MultiplyNumbers ()
{
cout << "Enter the first number : " ;
cin >> FirstNumber ;

cout << "Enter the second number : " ;
cin >> SecondNumber;

MultiplicationResult = FirstNumber * SecondNumber ;

cout << "Displaying from MultiplyNumbers(): " ;
cout << FirstNumber << " x " << SecondNumber ;
cout << " = " << MultiplicationResult << endl;

}
enum RainbowColors
{
Violet = 0 ,
Indigo,
Blue,
Green,
Yellow,
Orange,
Red

};

enum CardinalDirections
{
North,
South,
East,
West
};


int _tmain(int argc, _TCHAR* argv[])
{
const double Pi = 22.0 / 7 ;
cout << " The value of constant Pi is: " << Pi << endl;

cout << "Displaying directions and their symbpolic values" << endl;
cout << "North:" << North << endl;
cout << "South:" << South << endl;
cout << "East:" << East << endl;
cout << "West:" << West << endl;

CardinalDirections WindDirection = South;
cout << "Variable WindDirection = " << WindDirection << endl;

int MyNumbers [4] = {1,8,5,3};

int YourNumbers[] = {1,5,45,88,2,33,58};

const int ARRAY_LENGTH = 5 ;

int MyNumber1s [ARRAY_LENGTH] = {0} ;

cout << "Enter index of the element to be changed: " ;
int nElementIndex = 0 ;
cin >> nElementIndex;

cout << " Enter new value: " ;
cin >> MyNumber1s [nElementIndex];

cout << "First element at index 0 : " << MyNumber1s [0] << endl;
cout << "Second element at index 1 : "<< MyNumber1s [1] << endl;
cout << "Thirht element at index 2 : " << MyNumber1s [2] << endl;
cout << "Fourth element at index 3 : " << MyNumber1s [3] << endl;
cout << "Fifth element at index 4 : " << MyNumber1s [4] << endl;


int SolarPanelIDs [2][3] = {{1,3,2}, {2,3,5}}; // First [] is row Second is column

cout << "Row 0 : " << SolarPanelIDs [0][0] <<  " " \
 << SolarPanelIDs[0][1] << " " \
<< SolarPanelIDs [0][2] << endl;

cout << "Row 1 : " << SolarPanelIDs[1][0] << " " \
  << SolarPanelIDs[1][1] << " " \
  << SolarPanelIDs[1][2] << endl;

return 0;
}

댓글

주간 베스트

Vocabulary for IELTS (400 Words) master level

발표 전 심박수 안정 루틴

이들에게 팔면 절대 망하지 않는다: 타겟 마케팅의 핵심

서울대 교수 충격 발언 "AI 많이 쓰면 뇌 멍청해져