gpt4 book ai didi

c++ - 预期 `;' 之前 "pennies"? C++调试(代码完成)

转载 作者:太空狗 更新时间:2023-10-29 23:25:06 24 4
gpt4 key购买 nike

谁能告诉我为什么我在上次 cout 中出错?

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <cstring>
#include <conio.h>

using namespace std;
inline void keep_window_open() { char ch; cin>>ch; }

int main()
{
cout << "How many pennies do you have?\n";
int pennies;
cin >> pennies;
double total_pen;
total_pen = (0.01 * pennies);
if (pennies >= 1)
{
string penn = " pennies.";
}else
{
string penn = " penny.";
} cout << "How many nickles do you have?\n";
int nickles;
cin >> nickles;
double total_nic;
total_nic = (0.05 * nickles);
if (nickles >= 1)
{
string five = " nickels.";
}else
{
string five = " nickel.";
} cout << "How many dimes do you have?\n";
int dimes;
cin >> dimes;
double total_dim;
total_dim = (0.10 * dimes);
if (dimes >= 1)
{
string ten = " dimes.";
}else
{
string ten = " dime.";
} cout << "How many quarters do you have?\n";
int quarters;
cin >> quarters;
double total_qua;
total_qua = (0.25 * quarters);
if (quarters >= 1)
{
string twentyfive = " quarters.";
}else
{
string twentyfive = " quarter.";
} cout << "How many half-dollars do you have?\n";
int half_dollars;
cin >> half_dollars;
double total_dol;
total_dol = (0.50 * half_dollars);
if (half_dollars >= 1)
{
string fifty = " half dollars.";
}else
{
string fifty = " half dollar.";
}
string saying = "You have ";
cout << saying pennies penn << "\n" << saying nickles five << "\n" << saying dimes ten << "\n" << saying quarters twentyfive << "\n" << saying half_dollars fifty << "\n";
keep_window_open()
return 0;
}

最佳答案

添加更多<< :

cout << saying << pennies << penn << "\n" 
<< saying << nickles << five << "\n"
<< saying << dimes << ten << "\n"
<< saying << quarters << twentyfive << "\n"
<< saying << half_dollars << fifty << "\n";

编辑:此外,您在内部 block 中声明变量 - 它们的名称在外部不再有效。早点声明你的字符串。

关于c++ - 预期 `;' 之前 "pennies"? C++调试(代码完成),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4498365/

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