<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS94U2doVC5wbmcifQ==” alt =“在此处输入图像描述”>“ >>
你好。我对C ++和一般编程非常陌生。我试图通过玩弄一些我已经了解的小组件来建立自己的信心,直到我熟悉为止,然后再学习更多。但是我很沮丧,因为我似乎无法使这段简单的代码起作用。我希望任何阅读此书的人都能理解我正在尝试的尝试,并且可以告诉我哪里出了问题。谢谢,麻烦您了。
#include <iostream>
int main(int argc, const char * argv[]) {
char computer[100];
char something[100];
double price;
double price2;
double total = (price + price2);
double budget;
if (budget < total){ double need = total - budget;}
if (budget > total ){ double surplus = budget - total;}
double perday = total / 365;
double remain = budget - perday;
int A;
std::cout << "Please tell me, the 'name' of the new computer that you would like to buy.\n";
std::cin >> computer;
std::cout << " How much does this " << computer << " cost?\n";
std::cin >> price;
std::cout << "Cool! Now tell me something else you would like to buy.\n";
std::cin >> something;
std::cout << "How much does " << something << " cost?\n";
std::cin >> price2;
std::cout << "I need to know your technology budget:\n £";
std::cin >> budget;
if (budget >= total)
{std::cout << "Wow you have enough cash to get both " << computer << " and " << something << "\n with a surplus budget of £" << surplus;}
else (budget < total) {
std::cout << "I am sorry you lack the necessary funds right now. \n";
std::cout << "Would you like to hear a payment plan?\n 1 for yes / 2 for no \n";
std::cin >> A;
}
if (A = 1) {
std::cout << "If you wanted to buy both " << computer << " and " << something << " \n by this time next year, you could pay £" << perday << "each day from now\n ";
std::cout << "If I take today's payment now, you will have £" << remain << "left of your budget";}
else return 0;}
}
你好。我对C ++和一般编程非常陌生。我试图通过玩弄我已经了解的小组件来建立自己的信心,直到我像以前一样熟悉为止...
首先,在范围内声明变量是一个坏习惯,除非您计划仅在该范围内使用该变量。