@LukeZeller/

testing

C++

just testing

fork
loading
Files
  • main.cpp
main.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib> 
using namespace std; //adds std:: in front of commands?

#include <iomanip>
using std::setw;

const float VER = 1.6; //define version

int globalValue = 42, i; //init globalValue; global

int testFunction() {
  cout << "Function worked lol" << endl; //test if function worked

  cout << "This is a global value: " << globalValue << endl; //test globalValue

  return 0; //return nothing
}

int add2(int num1, int num2) { //num1, num2; local
  return num1 + num2; //add two nums
}

int main() {
  cout << "Version: " << VER << endl; //print version

  cout << "Hello World!" << endl; //prints hello world messsage

  int x = 10, theLetterX = 456; //init x, theLetterX; local

  cout << x << " plus 12 is: "; //out x, plus 12 is:

  x += 12; //add 12 to x

  cout << x << endl; //out x

  cout << theLetterX << endl; //out theLetterX

  bool iAmTired = true; //init iAmTired; local

  cout << "Am I Tired? " << iAmTired << endl; //out Am I Tired?, iAmTired

  testFunction(); //call function

  cout << "This is a global value: " << globalValue << endl; //test globalValue

  cout << add2(2, 6) << endl; //test add2

  string text = "text"; 

  cout << text << endl;

  int counter = 0; //init counter;local

  while(counter < 10) {
    cout << counter << endl; //print counter

    counter ++;
  }

  string input = ""; //init input

  cout << "Please enter some text (no spaces): ";

  cin >> input; //get an input

  cout << "Here is your text: " << input << endl; //print input

  cout << "I've never heard of a switch statement before. Lets try it." << endl << "Star-Lord(1) or Spiderman(2)?";

  int answer = 0;

  cin >> answer;
 
  switch(answer) {
    case 1 :
      cout << "He's relatable." << endl;

      break;
    case 2 :
      cout << "He's funny." << endl;

      break;
    default :
      cout  << "Thats not Star-Lord(1) or Spiderman(2)." << endl;
  }

  string hopefullyLetterL = "l";

  cout << hopefullyLetterL << endl;

  string answer2 = hopefullyLetterL == "l" ? "Yay!" : "Anger noises";

  cout << answer2 << endl;

  srand((unsigned)time(NULL));

  int randNum;

  for(i = 0; i < 3; i++) {
    randNum = rand();

    cout << "Random Number: " << randNum << endl;
  }

  int randNumArray[3];

  for(i = 0; i < 3; i++) {
    randNum = rand();

    randNumArray[i] = randNum;
  }

  cout << "Array of Random Numbers" << endl << "Element" << setw(13) << "Value" << endl;
                      
  for (int i = 0; i < 3; i++) {
    cout << setw(7)<< i << setw(13) << randNumArray[i] << endl;
  }

  string str1 = "Hello", str2 = "World", str3;

  int length;

  str3 = str1;

  cout << "str3: " << str3 << endl;

  str3 = str1 + str2;

  cout << "str1 + str2: " << str3 << endl;

  length = str3.size();

  cout << "str3 length:  " << length << endl;

  string *textAddress;

  textAddress = &text;

  cout << "Address of var text: " << textAddress << endl;

  cout << "Value of var text(via pointer): " << *textAddress << endl;

  return 0; //end program
}

//https://www.tutorialspoint.com/cplusplus/cpp_numbers.htm ;numbers