C++ not working fine

Hello everyone. I am a beginner of C++ Programming and I was given a task in the class today. It worked fine with the class computer but when I got home and tried it out with my laptop. There is a problem with the cin > n > m , can anyone please enlight me on the problem?

#include <iostream>
using namespace std;

main () {
int n, m;
cout <<"Enter two integers: \n";
cin >> n >> m ;

if (n > m) {
int temp = n;
n=m;
m = temp;
}

double sum = 1.0;

for (int i = n; i <= m ; i ++) {
sum *= 1 ;
}

cout << "Multiplication of integers between " << n << " and " << m << " is " << sum << '\n';
}



C:\Users\User\Desktop\Untitled1.cpp In function 'int main()':
7 6 C:\Users\User\Desktop\Untitled1.cpp [Error] no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'int')
7 6 C:\Users\User\Desktop\Untitled1.cpp [Note] candidates are:
53 0 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\string In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/string
40 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\locale_classes.h from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/bits/locale_classes.h
41 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\ios_base.h from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/bits/ios_base.h
42 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ios from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ios
38 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ostream
39 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream
1 C:\Users\User\Desktop\Untitled1.cpp from C:\Users\User\Desktop\Untitled1.cpp
996 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\basic_string.tcc [Note] template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
996 5 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\basic_string.tcc [Note] template argument deduction/substitution failed:
7 9 C:\Users\User\Desktop\Untitled1.cpp [Note] mismatched types 'std::basic_string<_CharT, _Traits, _Alloc>' and 'int'
43 0 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ios In file included from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ios
38 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\ostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/ostream
39 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\iostream from C:/Program Files (x86)/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/iostream
1 C:\Users\User\Desktop\Untitled1.cpp from C:\Users\User\Desktop\Untitled1.cpp
164 9 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\streambuf [Note] template<class _CharT2, class _Traits2> std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT2*)
164 9 C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\streambuf [Note] template argument deduction/substitution failed:
7 9 C:\Users\User\Desktop\Untitled1.cpp [Note] mismatched types '_CharT2*' and 'int'

I tested your program in the latest version of VS. You need to add a int before main.
int main () {
It would build after this so I tested no further. You said you were having trouble with your cin statement but it looks to work fine. Rember you have to leave a space between the integers when entering them.
closed account (LA48b7Xj)
Your for loop is just is multiplying 1.0 and 1 so the program will always output 1.
Topic archived. No new replies allowed.