-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeCastingDEMO.cpp
More file actions
35 lines (28 loc) · 1.04 KB
/
Copy pathTypeCastingDEMO.cpp
File metadata and controls
35 lines (28 loc) · 1.04 KB
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
//************************************************************************
// Author: Rolando Carreon
// Date: feb 06 2025
// Language: C++
// Assignment: Type Casting DEMO
// Description: casting data types
//************************************************************************
#include<iostream>
using namespace std;
int main()
{
// declare local variables //
// already defined varibales //
// int is single value //
int testOne = 89;
int testTwo = 98;
int testThree = 85;
// float is a more precise value or decimal //
float testAverage;
// calculate the test average //
// without static_cast<float> it will cout as a int unless..//
testAverage = static_cast<float>(testOne + testTwo + testThree) /3;
cout << "The average test grade is: " << testAverage << endl;
// ..you implicitly cast the int or '3' with a .0 to cast a float on the line //
testAverage = (testOne + testTwo + testThree) /3.0;
cout << "The second average test grade is: " << testAverage << endl;
return 0;
}