在代码中找到错误.... [英] find error... in the code
本文介绍了在代码中找到错误....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include < iostream.h >
使用 std :: cout;
使用 std :: cin;
int main();
{
int netsalary;
int basicsalary;
int 奖金;
int tax;
cout<< 请输入基本工资和奖金;
cin>> basicsalary;
cin>>奖金;
if (basicsalary< = 1000 )
tax = basicsalary * 10/100 ;
else tax = basicsalary * 20/100;
netsalary = basicsalary + bonus-tax;
cout<< netsalary;
return 0 ;
}
(enhzflep:已添加代码标签)
解决方案
< blockquote>你的编译器没有找到错误吗?
有几个...
例如
int main();
没时间对他们发表评论......
看看这本并开始阅读一本关于C ++的书。
#include < iostream >
< span class =code-keyword>使用 命名空间标准;
int main()
{
int netsalary;
int basicsalary;
int 奖金;
int tax;
cout<< 请输入基本工资:;
cin>>基础工资;
cout<< 和红利:;
cin>>奖金;
if (basicsalary< = 1000 )
tax = basicsalary * 10/100;
其他
tax = basicsalary * 20/100;
netsalary = basicsalary + bonus-tax;
cout<< netsalary;
return 0 ;
}
你真的想用int结果计算吗?
我的解决方案仅基于代码的静态分析
1.由于分割导致的整数数据类型导致截断
2.第二个输入(甚至第一个)值可能已损坏,因为用户可能不知道如何区分两个输入(空格,逗号等)
3.是否接受负值?
#include <iostream.h>
using std::cout;
using std::cin;
int main();
{
int netsalary;
int basicsalary;
int bonus;
int tax;
cout<<"please enter the basic salary and the bonus";
cin>>basicsalary;
cin>>bonus;
if ( basicsalary<=1000 )
tax=basicsalary*10/100;
else tax=basicsalary*20/100;
netsalary=basicsalary+bonus-tax;
cout<<netsalary;
return 0;
}
(enhzflep: code-tags added)
解决方案
Does your Compiler not find the errors ?
There are several of them ...
For exampleint main();
No time to comment them all ...
Take a look at this and start reading a book about C++.
#include <iostream> using namespace std; int main() { int netsalary; int basicsalary; int bonus; int tax; cout << "please enter the basic salary: "; cin >> basicsalary; cout << " and the bonus: "; cin >> bonus; if( basicsalary<=1000 ) tax=basicsalary*10/100; else tax=basicsalary*20/100; netsalary=basicsalary+bonus-tax; cout<<netsalary; return 0; }
Do you really want calculation with int result ?
My solution is based on only the static analyis of your code
1. Intger data types as a result of division oeration result in truncation
2. 2nd input ( or even 1st) values may be corrupted as user may not not know how to differentiate the two inputs ( space,comma etc)
3. Is Negative values accepted?
这篇关于在代码中找到错误....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文