如何解决没有错误,但是第二次输入后代码崩溃
我需要编写此程序来计算电影院在学校的利润。它最初是使用 cin编写的,但是随后我需要使用printf重写它。该代码有零个错误,在您输入成人票销售数量后,它只会崩溃。
router.get('/',function (req,res,next) {
async.parallel({
item1: function (callback) {
request1 = new Request('query',function(err,rowCount,rows) {
if (err) {
console.log(err);
}
});
var category = []
request1.on("row",columns => {
var category_item = {};
for (var name in columns) {
category_item[name] = columns[name].value;
}
category.push(category_item);
});
request1.on("doneInProc",(rowCount,more,rows) => {
callback(null,category);
});
con.execSql(request1);
},item2: function (callback) {
request2 = new Request('query',function (err,rows) {
if (err) {
console.log(err);
}
});
var category1 = [];
request2.on("row",columns => {
var category1_item = {};
for (var name in columns) {
category1_item[name] = columns[name].value;
}
category1.push(category1_item);
});
request2.on("doneInProc",rows) => {
callback(null,category1);
});
con.execSql(request2);
},},results) {
res.end(JSON.stringify(results));
});
});
}`
解决方法
Scanf需要一个指向整数的指针,而不是整数本身,请尝试对其进行更改:
int AdultSales,ChildrenSales;
printf("How many adults attended? ");
scanf(" %d",&AdultSales);
printf("How many children attended? ");
scanf(" %d",&ChildrenSales);
您可以在此处看到函数参考:http://www.cplusplus.com/reference/cstdio/scanf/
,我认为您想这样做是因为错误已得到纠正
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{ char movie[50];
printf("What is the name of the movie?");
scanf(" %s",movie);
int AdultSales,&AdultSales); //scanf(" %d",AdultSales);
printf("How many children attended? ");
scanf(" %d",&ChildrenSales); //scanf(" %d",ChildrenSales);
float GrossBoxOfficeProfit= ChildrenSales*9.25+AdultSales*11.25;
float AmountPaidToDistributer=GrossBoxOfficeProfit*0.8;
float NetBoxOfficeProfit=GrossBoxOfficeProfit-AmountPaidToDistributer;
printf("movie: %s",movie);
printf("\nAdult tickets sold: %d",AdultSales);
printf("\nChild ticket sold: %d",ChildrenSales);
printf("\nGross Box office profit: %f",GrossBoxOfficeProfit);
printf("\nNet Box office profit: %f",NetBoxOfficeProfit);
printf("\nAmount paid to distributer: %f",AmountPaidToDistributer);
return 0;
}
这部分是错误的
//scanf("movie: %s",movie);
//scanf("\nAdult tickets sold: %d",AdultSales);
//scanf("\nChild tickest sold: %d",ChildrenSales);
//scanf("\nGross Box office profit: $%f",GrossBoxOfficeProfit);
//scanf("\nNet Box office proft: $%f",NetBoxOfficeProfit);
//scanf("\nAmount paid to distributer: $%f",AmountPaidToDistributer);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。