2017-01-21 18 views
-2

私のプログラムにちょっとした助けが必要でした。 if文でエラーが発生し続けます。 お願いします。 これは私が書いたコードです。エラー(ISO C++はポインタと整数の比較を禁止しています)[-fperemissive]

#include <iostream> 
 
#include <cstdlib> 
 
#include <iostream> 
 
#include <string> 
 

 
char carChoice; 
 
int random_integer = rand(); 
 
int pricePerDay; 
 
int daysOfHire; 
 
int totalCost; 
 
int age; 
 
int telephoneNumber[30]; 
 
char name[30]; 
 
char address[30]; 
 
char response [4]; 
 

 

 
using namespace std; 
 

 
int main() 
 

 
{ 
 
    cout << "Royal Rentals" << endl; 
 
    cout << "---------------------------------------------"<<"\n" <<endl; 
 
    cout << "Current Stock: " <<endl; 
 
    cout << "A - Lamborghini Aventador" <<endl; 
 
    cout << "B - Lamborghini Huracan" <<endl; 
 
    cout << "C - Mercedes Benz AMG GT S" <<endl; 
 
    cout << "D - Audi R8 V10" <<endl; 
 

 
cout << "Which car would you like to rent (A, B, C or D)" << "\n" << endl; 
 
cin >> carChoice; 
 
cout << "How many days would you like to hire the car for" << "\n" << endl; 
 
cin >> daysOfHire; 
 
cout << "How old are you?" << "\n" << endl; 
 
cin >> age; 
 

 

 
if (age < 21) 
 
{ 
 
    cout << "Sorry but you have to over the age of 21 to hire our super cars" << "\n" << endl; 
 
    cout << "Please close the program to hire a car suitable for your age" << "\n" << endl; 
 
    exit (0); 
 
} 
 

 
cout << "What is your name?" << "\n" << endl; 
 
cin >> name; 
 
cout << "Have you got a full drivers license?" "\n" << endl; 
 
cin >> response; 
 

 
if (response == 'Y' //not "Y" but only one 'Y') 
 
{ 
 
cout << "blah"<< "\n" <<endl; 
 
} 
 
else if (response == 'N') 
 
{ 
 
cout << "blah"<< "\n" << endl; 
 
} 
 

 
cout << "what is your address?" << "\n" << endl; 
 
cin >> address; 
 
cout << "what is your telephone number?"<< "\n" << endl; 
 
cin >> telephoneNumber; 
 

 
if (carChoice == 'a') 
 
{ 
 
    totalCost = daysOfHire * 685; 
 
    cout << "You have chosen the following car for hire: Lamborghini Aventador" << endl; 
 
    cout << "The price per day is 685.00 GBP" << endl; 
 
    cout << "The Total Cost is: " << totalCost << endl; 
 
    cout << "Invoice Number; " << random_integer << endl; 
 
} 
 
else if (carChoice == 'b') 
 
{ 
 
    totalCost = daysOfHire * 585; 
 
cout << "You have chosen the following car for hire: Lamborghini Huracan" << endl; 
 
cout << "The price per day is �585.00 GBP" << endl; 
 
cout << "The Total Cost is: " << totalCost << endl; 
 
cout << "Invoice Number; " << random_integer << endl; 
 
} 
 
else if (carChoice == 'c') 
 
{ 
 
    totalCost = daysOfHire * 485; 
 
cout << "You have chosen the following car for hire: Mercedes Benz AMG GT S" << endl; 
 
cout << "The price per day is �485.00 GBP" << endl; 
 
cout << "The Total Cost is: " << totalCost << endl; 
 
cout << "Invoice Number; " << random_integer << endl; 
 
} 
 
else if (carChoice == 'd') 
 
{ 
 
    totalCost = daysOfHire * 445; 
 
cout << "You have chosen the following car for hire: Audi R8 V10" << endl; 
 
cout << "The price per day is �445.00 GBP" << endl; 
 
cout << "The Total Cost is: " << totalCost << endl; 
 
cout << "Invoice Number; " << random_integer << endl; 
 
} 
 
else 
 
{ 
 
cout << "You have entered an invalid response" << endl; 
 
} 
 
}

文は、有効な運転免許証を持っている場合は、プログラムはメッセージと密接に表示する必要があるない場合は、確認することです。彼らがそうするなら、彼らは彼らの細部の残りを入力することができるように続けるべきです。 私はそれに欠けているものと、if文を修正するものがあります。

多くのおかげで、 Irbaaz

+2

[mcve]を入力するように質問してください。 –

+0

応答は配列です。配列は比較できません。 strcmpやstd :: stringなどのCスタイルの関数を使う必要があります。 –

+1

私はプログラミングがかなり新しいです。では、私は何を変える必要がありますか? –

答えて

0
if (response == 'Y') 

応答が配列である、あなたは、整数の配列を比較することはできません。文字列全体が1つの「Y」記号で構成されていることを確認する場合は、チェックしてください。

Strlen(response) == 1 && response[0] == 'Y' 
関連する問題