2.x Quiz
This commit is contained in:
parent
9bf81f1adc
commit
b21c717fdd
4 changed files with 24 additions and 12 deletions
|
@ -9,7 +9,7 @@
|
||||||
"-ggdb",
|
"-ggdb",
|
||||||
"-std=c++20",
|
"-std=c++20",
|
||||||
"-pedantic-errors",
|
"-pedantic-errors",
|
||||||
"${file}",
|
"${fileDirname}/**.cpp",
|
||||||
"-o",
|
"-o",
|
||||||
"${fileDirname}\\build\\${fileBasenameNoExtension}.exe"
|
"${fileDirname}\\build\\${fileBasenameNoExtension}.exe"
|
||||||
],
|
],
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
"-DNDEBUG",
|
"-DNDEBUG",
|
||||||
"-std=c++20",
|
"-std=c++20",
|
||||||
"-pedantic-errors",
|
"-pedantic-errors",
|
||||||
"${file}",
|
"${fileDirname}/**.cpp",
|
||||||
"-o",
|
"-o",
|
||||||
"${fileDirname}\\build\\${fileBasenameNoExtension}.exe"
|
"${fileDirname}\\build\\${fileBasenameNoExtension}.exe"
|
||||||
],
|
],
|
||||||
|
|
14
io.cpp
Normal file
14
io.cpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#include "io.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int readNumber()
|
||||||
|
{
|
||||||
|
std::cout << "Enter a number to add: ";
|
||||||
|
int x{};
|
||||||
|
std::cin >> x;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
void writeAnswer(int x)
|
||||||
|
{
|
||||||
|
std::cout << "The answer is: " << x << "\n";
|
||||||
|
}
|
4
io.h
Normal file
4
io.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
int readNumber();
|
||||||
|
void writeAnswer(int x);
|
14
main.cpp
14
main.cpp
|
@ -1,17 +1,11 @@
|
||||||
#include <iostream> // for std::cout
|
#include <iostream> // for std::cout
|
||||||
|
#include "io.h"
|
||||||
// Definition of user-defined function doPrint()
|
|
||||||
void doPrint() // doPrint() is the called function in this example
|
|
||||||
{
|
|
||||||
std::cout << "In doPrint()\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Definition of function main()
|
// Definition of function main()
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
std::cout << "Starting main()\n";
|
int a{readNumber()};
|
||||||
doPrint(); // Interrupt main() by making a function call to doPrint(). main() is the caller.
|
int b{readNumber()};
|
||||||
std::cout << "Ending main()\n"; // this statement is executed after doPrint() ends
|
writeAnswer(a + b);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue