帮我找错误,,谢谢。我是C++初学者,把书上的代码输入编译器中,总是显示有一个错误,可是找不出来。

2024-12-22 12:57:31
推荐回答(4个)
回答1:

直接复制你的程序编译 没发现问题
运行结果
press return after entering a number.
enter the number of pods:
3
enter the number of peas in a pod:
4
if you have3and4peas in each pod,then
you have12peas in all the pods.

你把错误信息发上来看下

回答2:

头文件前面加上#include"stdafx.h"
如这样,我这里行了。

#include"stdafx.h"
#include
using namespace std;
int main()
{
int number_of_pods,peas_per_pod,total_peas;
cout << "press return after entering a number.\n";
cout << "enter the number of pods:\n";
cin >> number_of_pods;
cout << "enter the number of peas in a pod:\n";
cin >> peas_per_pod;
total_peas=number_of_pods*peas_per_pod;
cout << "if you have";
cout << number_of_pods;
cout << "and";
cout << peas_per_pod;
cout << "peas in each pod,then\n";
cout << "you have";
cout << total_peas;
cout << "peas in all the pods.\n";
return 0;
}

回答3:

把错误提示贴出来啊

回答4:

我编译了一下,木有问题,你用的什么编译器?
你把提示信息也发上来