Justin's Words

第一个 C++ 程序

实际上是来自 Learn Cpp.Com 的 o(^▽^)o

io.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>

double readNumber()
{
using namespace std;
double nInput;
cout << "Enter a number: ";
cin >> nInput;
return nInput;
}

void writeAnswer(double answer)
{
using namespace std;
cout << "The answer is " << answer << endl;
}

io.h

1
2
3
4
5
6
7
#ifndef IO_H
#define IO_H

double readNumber();
void writeAnswer(double answer);

#endif

main.cpp

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include "io.h"

int main()
{
using namespace std;
double nInput1 = readNumber();
double nInput2 = readNumber();
writeAnswer(nInput1 + nInput2);
system("pause");
return 0;
}