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",
|
||||
"-std=c++20",
|
||||
"-pedantic-errors",
|
||||
"${file}",
|
||||
"${fileDirname}/**.cpp",
|
||||
"-o",
|
||||
"${fileDirname}\\build\\${fileBasenameNoExtension}.exe"
|
||||
],
|
||||
|
@ -30,7 +30,7 @@
|
|||
"-DNDEBUG",
|
||||
"-std=c++20",
|
||||
"-pedantic-errors",
|
||||
"${file}",
|
||||
"${fileDirname}/**.cpp",
|
||||
"-o",
|
||||
"${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
|
||||
|
||||
// Definition of user-defined function doPrint()
|
||||
void doPrint() // doPrint() is the called function in this example
|
||||
{
|
||||
std::cout << "In doPrint()\n";
|
||||
}
|
||||
#include "io.h"
|
||||
|
||||
// Definition of function main()
|
||||
int main()
|
||||
{
|
||||
std::cout << "Starting main()\n";
|
||||
doPrint(); // Interrupt main() by making a function call to doPrint(). main() is the caller.
|
||||
std::cout << "Ending main()\n"; // this statement is executed after doPrint() ends
|
||||
|
||||
int a{readNumber()};
|
||||
int b{readNumber()};
|
||||
writeAnswer(a + b);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue