gpt4 book ai didi

C++- If 语句问题。代码将不会运行 else 或 else if

转载 作者:行者123 更新时间:2023-11-28 01:47:31 25 4
gpt4 key购买 nike

<分区>

我将在下面输入我的代码。作为免责声明,我是一个完全的新手,我知道我的代码布局非常糟糕,我应该创建函数......现在我保持简单。

我的问题是我的 if 语句将运行“if”部分,但不会运行“else if”部分。感谢您的帮助。

我的代码:

// Coding Challenges.cpp : Defines the entry point for the console 
application.
//
#include "cstdlib"
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

char responses(char user_response)
{
return user_response;
}

int main()
{
char responses;
char user_response;
cout << "Welcome to the tempature conversion program." << endl;
cout << "Please type F to convert from farenheit to celcius or C for celcius
to farenheit." << endl;
//getchar(user_response);
cin >> user_response;
getchar();
cout << "You entered: " <<user_response << endl;


switch (user_response) {
case 'F':
cout << "You have chosen to convert from farenheit to celcius." << endl;
break;

case 'C':
cout << "You have chosen to convert from celcius to farenheit." << endl;
break;

default:
cout << "Woops. It Looks like you haven't entered correctly." << endl;
break;
}
getchar();
cout << "Code should have ran " << endl;
getchar();
cout << "You entered: " << user_response << endl;
getchar();

if (user_response = 'F') {
double f_val = 0;
cout << "Please enter the value of farenheit you would like to convert:
" << endl;
cin >> f_val;
cout << f_val;
getchar();
getchar();


} else if (user_response = 'C') {
double c_val = 0;
cout << "Please enter the value of celcius you would like to convert: "
<< endl;
cin >> c_val;
cout << c_val;
getchar();
getchar();


} else {
cout << "Error" << endl;
return 0;
getchar();
getchar();
}
getchar();
getchar();

return 0;
}

忽略我明显用于测试/调试的任何代码。

谢谢,

泰德

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com