-1
基本的なC++チャレンジ(C++の初心者)を試みて、このコードを生成しました。私は配列から値を呼び出すことはゼロから始まると理解していますが、私は簡単なルートに行きたくないので、ユーザーが0から4の代わりに1-5からタイプすることを望んでいました。私の関数は一見無意味にスキップされています
これは私の問題です。ユーザーが1-5を入力できるように1を引く基本的な機能を作ったが、配列は値を1-4と見なす。しかし、この画像に示されているように、私の機能を無視し、コードの次の部分にスキップしているようです。私は以下のコードを含んでいます。
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
string drink[5] = { "Coke", "Water", "Sprite", "Monster", "Diet Coke" };
int choice;
int correct = 0;
void AdjArray()
{
choice--;
};
int main()
{
while (correct != 1)
{
cout << "Enter the number of the beverage you would like." << endl;
cout
<< " Coke = 1\n Water = 2\n Sprite = 3\n Monster = 4\n Diet Coke = 5"
<< endl;
cin >> choice;
AdjArray;
if (choice >= 0 && choice <= 4)
{
cout << "You have chosen " << drink[choice] << "." << endl;
correct = 1;
}
else
{
system("cls");
cout << "Error, you entered: " << choice
<< ". Please enter a number between 1 and 5.\n" << endl;
}
}
return 0;
}
AdjArrayを呼び出しているように見えません。機能を呼び出すには括弧が必要です –
コンピュータがあなたを迫害していますか?いいえ、あなたの前提と現実の間には常に不一致があります。コードが間違っていて、そこにバグを入れてしまいます。デバッガのスピンが光を表示します。 – duffymo
@ GarrettRが述べるように、あなたはこのような関数を 'AdjArray();'のように呼び出します。 –