asked 218k views
4 votes
Submit a C++ program that uses all its primitive data types and program/logic flow controls. Make your own original codes showing the use of the said data types and program controls.​

1 Answer

5 votes

```cpp

#include <iostream>

using namespace std;

int main() {

// Variables of different data types

int myInt = 10;

float myFloat = 3.14;

char myChar = 'A';

bool myBool = true;

// Outputting the values of the variables

cout << "myInt: " << myInt << endl;

cout << "myFloat: " << myFloat << endl;

cout << "myChar: " << myChar << endl;

cout << "myBool: " << myBool << endl;

// If-else statement

if (myInt > 5) {

cout << "myInt is greater than 5." << endl;

} else {

cout << "myInt is less than or equal to 5." << endl;

}

// For loop

for (int i = 0; i < 5; i++) {

cout << "Iteration " << i+1 << endl;

}

// While loop

int count = 0;

while (count < 3) {

cout << "Count: " << count << endl;

count++;

}

return 0;

}

```

In this program, we have used various primitive data types such as `int`, `float`, `char`, and `bool`. We declared variables of these types and assigned them values.

We then used the `cout` statement to output the values of the variables.

Next, we used an `if-else` statement to check if the value of `myInt` is greater than 5. Depending on the condition, it will print a corresponding message.

We also used a `for` loop to iterate 5 times and print the iteration number.

Lastly, we used a `while` loop to count up to 3 and print the current count.

By using these data types and program control flow statements, you can perform various operations and create more complex programs in C++.

answered
User Edward Shtern
by
8.3k points

No related questions found