gpt4 book ai didi

c++ - 需要帮助调试我的第一个程序,Visual Studio 找不到 .exe 文件。

转载 作者:行者123 更新时间:2023-11-30 02:52:27 26 4
gpt4 key购买 nike

这是我的第一个计算通勤费用的程序。 Visual Studio 在调试时遇到问题,因此我正在寻求帮助...

#include <iostream>
using namespace std;

int main()
{

int miles, gallons, gallonCost, mpg, mileCost, parking, tolls, FuelCost, TotalCost = 0.0;

谁能解释一下上面这行代码在做什么(或不做什么),这是制作浮点整数列表的正确方法吗?

cout << " How many miles do you drive per day? ";
cin >> miles;

cout << " What is the price per gallon of fuel? ";
cin << gallonCost;

cout << " How many gallons of fuel do you use per day? ";
cin >> gallons;

mpg = miles / gallons;
mileCost = gallonCost / mpg;

cout << " Your fuel efficentcy is " << mpg ;" miles per gallon. ";
cout << " Your fuel cost is $" << mileCost ;" per mile. ";

FuelCost = mileCost * miles;

cout << " Your paying $" << FuelCost ;" for fuel per day.";

cout << " What are you daily parking fees? ";
cin << parking;

cout << " How much do you spend on Tolls each day? ";
cin >> tolls;

TotalCost = parking + tolls + FuelCost;

cout << " Your driving cost is $" << TotalCost ;" per day." endl;

system("PAUSE");
return 0;
}

提前致谢

最佳答案

不,这不是创建浮点变量的方法,而是创建整数变量的方法。没有“ float ”这样的东西。

你还应该得到很多关于表达式没有做任何事情的警告,就像在行中一样

cout << " Your fuel efficentcy is " << mpg ;" miles per gallon. ";
// Problem here ^

那是因为你在行的中间多了一个分号,从而终止了输出语句。然后编译器找到一个字符串,它与表达式相同,所以没关系,但不会做任何应该引起警告的事情。我怀疑您想要输出运算符 << 而不是额外的分号.

你应该在这一行得到一个错误:

cout << " Your driving cost is $" << TotalCost ;" per day." endl;
// Error here ^

该错误是因为您有一个字符串后跟一个标识符。这不是一个有效的表达式。您可能忘记了输出运算符 <<在这里。

这是导致构建过程无法创建可执行文件的最后一个错误,因此您无法运行/调试。始终注意编译器生成的消息,即使是警告也会告诉您一些有用的信息。

关于c++ - 需要帮助调试我的第一个程序,Visual Studio 找不到 .exe 文件。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18910988/

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