Challenge: Let C++ Do the Maths
Completed
Print the line 12 + 30 = 42. Write the text 12 + 30 = in quotes, but let C++ calculate the 42 from 12 + 30.
Input
None.
Output
One line: 12 + 30 = 42
Example
Output
12 + 30 = 42
Editor
C++
Hints
Chain two pieces with <<: the text, then the sum.
Don't put quotes around 12 + 30 the second time.
Solution explanation
Text in quotes is printed as it is. 12 + 30 without quotes is worked out first, so 42 is printed.
Show solution
#include <iostream>
using namespace std;
int main() {
cout << "12 + 30 = " << 12 + 30 << "\n";
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module