+ 1

Why short double doesn't work?

// находит сумму всех положительных чисел массива #include <iostream> #include <cmath> using namespace std; int main() { int n = 6, i=0; short double sum =0; // the compiler swears at this line double arr[n] = {2.3, -4, 6, 7, 1.23, 14}; // перебирает элементы массива while (i < n){ if (arr[i] > 0) sum+=arr[i]; i++; } cout <<"Sum of positive numbers = "<< sum << endl; return 0; }

22nd Jan 2021, 2:42 PM
Aibek Zhaisanbay
Aibek Zhaisanbay - avatar
4 Answers
+ 4
`short` is one of the type modifiers in C/C++ that changes the related type storage space & data range. As I understand it, `short` is only applicable to integer type (`double` is floating point type). For more info about modifiers, please refer the following link https://www.techcrashcourse.com/2015/11/modifiers-in-c-constants-data-types-c.html
22nd Jan 2021, 3:12 PM
Ipang
+ 2
There is no `short double` type as I understand it. There's `long double` however, maybe you meant to use that one instead.
22nd Jan 2021, 2:59 PM
Ipang
+ 2
Really?! Ohh, thank you very much, and with what data types can you use "short"?
22nd Jan 2021, 3:05 PM
Aibek Zhaisanbay
Aibek Zhaisanbay - avatar
+ 2
I am very grateful to you!!!
22nd Jan 2021, 3:35 PM
Aibek Zhaisanbay
Aibek Zhaisanbay - avatar