简体   繁体   English

我无法弄清楚我的代码没有显示预期结果的问题

[英]I can't figure out the problem with my code not showing expected results

Write a program that gets two positive single digit integers from the user.编写一个程序,从用户那里获取两个正的个位数整数。 Then print all the numbers from 1 to 1,000 that are divisible by both of those integers.然后打印从 1 到 1,000 的所有可以被这两个整数整除的数字。 Print ten numbers per line and separate them by a tab.每行打印十个数字并用制表符分隔。 ('\t') ('\t')

I have done a code to print numbers from 1 - 1000 that are divisible by two numbers, x and y.我已经编写了一个代码来打印 1 - 1000 的数字,这些数字可以被两个数字 x 和 y 整除。

#include <iostream> using namespace std; int main() {

int x, y;
cout << "Enter two positives single digit integers: ";
cin >> x >> y;
    for (int i = 1; i <= 1000; i++) {
        if ( i % x == 0 && i % y == 0)
            cout << i << '\t';
            if (i % 10 == 9)
            cout << endl;
        else i++;    
    }
    return 0; }

I'm not getting any results that I need for my code.我没有得到我的代码所需的任何结果。 Expected results:预期成绩:

Enter two positive single digit integers: 5 6
30  60  90  120 150 180 210 240 270 300
330 360 390 420 450 480 510 540 570 600
630 660 690 720 750 780 810 840 870 900
930 960 990

The 'i%10 ==9' should be a 0 and not a 9 since you want that after a number divisible by 10 (meaning that there is no remainder) you end the line. 'i%10 ==9' 应该是 0 而不是 9,因为您希望在可被 10 整除的数字之后(意味着没有余数)结束该行。 Second iterating i in the for loop is wrong since this is what a for loop initially does.在 for 循环中第二次迭代 i 是错误的,因为这是 for 循环最初所做的。 This is just some bad basics, try rereading c++ introduction books or watching more tutorials.这只是一些糟糕的基础知识,请尝试重读 c++ 介绍书籍或观看更多教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法弄清楚我的代码有什么问题 - I can't figure out what's wrong with my code 我有一个错误与我的for循环,不能找出为什么,我有一个“预期声明”错误 - I am having an error with my for loop and can't figure out why, I have an “expected declaration” error 我不知道为什么我的 while 循环没有给出预期的结果): - I can't figure out why my while loop is not giving the expected result ): 我不明白为什么我的代码不显示字符而不是 ASCII 值 - I can't figure out why my code isn't displaying a character instead of a ASCII Value 我不明白为什么我的代码出现段错误 - I can't figure out why I'm getting a seg fault in my code 我的代码没有编译,任何人都可以帮我弄清楚我做错了什么? - My Code isn't compiling, can anyone help me figure out what I'm doing wrong? 项目Euler#8,我无法弄清楚为什么我的代码给出了高得离谱的值 - Project Euler #8, I can't figure out why my code gives absurdly high values 我无法弄清楚为什么在我的 C++ 代码中会发生这种情况 - I can't figure it out why this happen in my C++ code 我无法弄清楚我的合并排序代码怎么了? - What is wrong with my merge sort code, I can't figure out? 无法弄清楚我的代码中有什么问题 - Can't figure out what's wrong in my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM