【发布时间】:2015-05-20 20:52:57
【问题描述】:
我目前正在制作一个程序,要求用户输入两个整数并比较它们是否正确。我需要帮助编写这个程序。 (对不起,我是 C++ 新手)。
例如,这是我想要的输出。
输入你的正整数:123
输入你的正整数:124
数字 1:123
数字 2:124
比较次数:3
3 -- 4(不正确)
2 -- 2(正确)
1 -- 1(正确)
到目前为止我有这个代码:
void twoInt()
{
int first, second;
cout << "\n\nEnter your positive integer : ";
cin >> first;
cout << "\nEnter your positive integer : ";
cin >> second;
cout << "\n\nNumber 1: " << setw(10) << first;
cout << "\nNumber 2: " << setw(10) << second;
// how do i compare each digit that user has entered
//through keyboard and compare them to first and second integer variable
fflush(stdin);
cin.get();
}
我应该使用哪个内置函数通过 for 循环进行比较?
提前致谢!任何提示和帮助将不胜感激!
【问题讨论】:
-
提示:
123%10==3和124%10==4