我正在编写一个程序来处理贷款。问题是它只读取第一个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