编写在另一个.cpp文件中调用的函数

时间:2018-02-27 03:25:38

标签: c++ shuffle

我想确保我正确调用函数。另一个.cpp中的函数是makeDeck()shuffle()。我也不知道如何制作相关的头文件或何时有用。有人可以编写或引导我查看将使用以下内容的deck.cppdeck.h文件的语法: main.cpp

#include <iostream>
#include "deck.h"
using namespace std;


int main() {
  int size;
  do {
    cout << "Enter size of deck (5-50): " << endl;
    cin >> size;
  } while (size<5 || size>50);

  int** deck[size] = makeDeck(size);
  shuffle(deck);

  int score = 0;
  char guess = NULL;

  for (int** i = **deck; *i != NULL; i++) {
    cout << "Score: " + score << endl;
    cout << "Current card: " + *i<< endl;
    cout << "Will the next card be higher (high) or lower (low) than " + *i + "?" << endl;
    cin << guess;
    if (guess == "higher" || guess == "high") {
      if (*(i + 1) > *i)
        score++;
      else
        score--;
    }
    if (guess == "lower" || guess == "low") {
      if (*(i + 1) < *i)
        score++;
      else
        score--;
    }
  }
}

0 个答案:

没有答案