简单c++程序Id的问题返回1退出状态
Problems with simple c++ program-Id returned 1 exit status
所以我这样做是为了学校,我不知道问题出在哪里程序的任务是读取输入的数字,然后像123一样从后面开始写,它会返回321我写的代码对我来说似乎很好,但唯一的错误是Id返回1退出状态。我完全不知道这么小的代码会有什么错这里是。为了更容易理解,Nc是数字,s是乘数。c就像我在while循环中从n除以10之前提取的最后一个数字。n是输入数,n1是所需数。
int main(int argc, char** argv) {
int n,nc,n1,c,s;
printf("Enter number: n");
scanf("%d",&n);
while(n>0){
n/=10;
nc+=1;
}
s=pow(10,nc);
while(n>0){
c=n%10;
n1+=c*s;
s/=10;
n/=10;
}
printf("New number is %d",n1);
system("pause");
return 0;
}
int string2int(string input)
/// converts a string into an integer
{
int output = 0;
unsigned len = input.length();
for (unsigned i = 0; i < len; i++)
{
char u = input[i]; // getting char from string
int y = int(u); y -= '0'; // using character subtraction to make int
output += y * pow(10, len - i - 1); // moving digit to appropriate spot
} // the len - i - 1 is what makes the output go in correct order
return output;
}
需要注意的是,pow在这种情况下是我创建的一个函数,它只是使用一个循环,如果你想使用标准的pow,你应该对结果进行四舍五入,还应该注意这个函数使用字符串。
为了阅读用户的输入,我建议使用std::cin,它使用与std::cout类似的语法,并且更方便
相关文章:
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 试图在崇高中奔跑. 错误 已发生: 收集2.exe: 错误: ld 返回 1 退出状态
- C++ collect2:错误:ld 返回 1 退出状态
- 找不到 -llibmysqld Collect2.exe:错误:ld 返回 1 退出状态
- 每次我要使用外部资源时,我都会得到:collect2。exe:错误 ld 返回 1 退出状态
- 使用类[错误] LD返回1退出状态
- 生成文件gtkmm;collect2.exe:错误:ld返回1退出状态
- C++:"错误收集 2:错误:ld 返回 1 退出状态"
- 无法导出mexfunction:符号未定义的collect.exe2.exe:错误:ld返回1退出状态
- 开发人员在Dev C 中编译代码时,我会收到此错误:[错误] ID返回1退出状态
- 简单c++程序Id的问题返回1退出状态
- ..未定义对..的引用..collect2:ld返回1退出状态
- collect2.exe:错误:ld在编译带有gradle 2.3的C++代码时返回1退出状态
- Tic-Tac-Toe C++链接错误ld返回1退出状态
- 错误:找不到体系结构x86_64的符号,collect2:ld返回1退出状态
- 流权限被拒绝,id返回1退出状态
- Ld返回1退出状态链接错误
- C++编译错误:取消定义对'printMaze(int const(*)[16],int,int)'的引用,Id 返回 1 退出状态
- collect2.exe[错误]ld返回1退出状态
- 对静态常量变量的未定义引用collect2: ld返回1退出状态