我正在編寫一個程序來處理貸款。問題是它只讀取第一個if
語句,然後執行讀取"("Thank you,your loan is being processed")"
程序的最後一句,我該如何糾正?它跳過評估用戶輸入的部分。這是代碼。C++程序只執行第一個「if」語句
#include<stdio.h>
#include<sstream>
#include<iostream>
#include <conio.h>
#include <string.h>
using namespace std;
int main() {
char landtitle[100];
char Asset[100];
//std::string Asset;
float NumberPlate;
float Year;
char L[100];
char t[100];
float amount;
float logbook;
float block;
float PlotNumber;
//float InterestRate;
float LoanAmount;
//LoanAmount = amount * (1+(15/100))*(1+(15/100));
//printf("Amount to be paid after one month is %f",LoanAmount);
printf("Enter amount you want to borrow");
printf("\nWe wil need an asset for any amount greater than 3M:");
scanf("%d",&amount);
if (amount > 3000000)
{
printf("Please choose Asset(use L for logbook or T for title");
//getline(cin,Asset);
gets(Asset);
//cin.ignore();
if (Asset == "L")
{
printf("\nPlease enter logbook number :");
scanf("%f",&logbook);
printf("\nPlease enter car Number plate :");
scanf("%f",&logbook);
printf("\nPlease enter Year of manufacture :");
scanf("%f",&logbook);
//printf("Thank you,your loan is being processed");
}
else
{
printf("\nPlease enter Land title :");
gets(landtitle);
printf("\nPlease enter Block :");
scanf("%f",&block);
printf("\nPlease enter Plot Number :");
scanf("%f",&PlotNumber);
//printf("Thank you,your loan is being processed");
}
}
else
{
printf("Thank you,your loan is being processed");
}
}
你不應該使用'得到()',其中有緩衝區溢出的風險不可避免。另外C風格的字符串不能通過'=='進行比較,所以應該使用'strcmp()'。 – MikeCAT
@ MikeCAT。我應該用什麼來代替get()來捕獲字符串或char。 – brayo
你正在使用C++,所以'std :: string Asset; std :: getline(std :: cin,Asset);'很好。 – MikeCAT