Pages: 12
Hello, can u help me answer this.
Make a program that asks user to input array of numbers (positive and negative) and will identify the smallest positive numbers from these input. Display the result.
Last edited on
effort what
#include <iostream>
#include <valarray>
using V = std::valarray<double>;
int main()
   V a = { 14, -2.5, 12, 3.3, -1.6, 0 };
   std::cout << V( a[a>0.0] ).min();

Last edited on
#include <iostream>
#include <limits>

int main() {
	size_t noNums {};
	int small {std::numeric_limits<int>::max()};

	std::cout << "How many numbers to enter: ";
	std::cin >> noNums;

	std::cout << "Please enter " << noNums << " integers: ";

	for (size_t i = 0; i < noNums; ++i) {
		int no {};

		std::cin >> no;

		if (no < small)
			small = no;

	std::cout << "The smallest number entered is " << small << '\n';

... well it is Christmas!
@seeplus, i am using DevC++ and the code u sent, cant run in this IDE. What should I do?
Last edited on
I use VS2022 C++20 and it compiles OK for me. I don't use DevC++. What version of the compiler are you using?
What should I do?

1. Read the errors

2. Understand why the code is giving you those errors

3. Work out how to fix your code

In other words, it's time for you to do some work, rather than asking others to do it for you!
The code seeplus wrote requires at most C++11, for the variable initialization on lines 5-6. That is "uniform initialization."

Everything else predates C++11.

Depending on what version of Dev-C++ being used C++11 is possible. Nothing higher. No C++14/17/20.

The original Bloodshed version is the only version I know of that would choke on that code. Orwell's version uses TDM-GCC 4.9.2. That is almost as old as dirt, though it still can compile without a hitch the above code. I know, I tried it in my Orwell Dev-C++.

I can't remember if ISO C++11 is the default when starting a new console project, with my copy it is.

The code lastchance wrote is also error-free in Orwell Dev-C++ as well.

Check your project options. Compiler, code generation, language standard. If it isn't ISO C++11 then change it.

There are two newer ports of the Dev-C++ IDE, Red Panda and Embarcadero. The Embarcadero port uses TDM-GCC 9.2.0, Red Panda uses WinGW64-W64 GCC 10.2.

Neither of the newer Dev-C++ ports will install on my Win10x64 development machine, so I can't really say if they are better than Orwell's outdated version.

One problem with Dev-C++ is trying to install a newer version of the compiler isn't easy, if at all possible. I've tried in the past and couldn't do it without wrecking the original preinstalled compiler. That made Dev-C++ unusable.

There are other free IDEs available, the two common ones for Windows are Visual Studio 2019/2022 and Code::Blocks. Getting and using a C++20 compliant compiler is easy. With VS there are updates that can be applied, C::B can be tweaked to use a different compiler. My copy of C::B uses the MSYS2 MinGW compiler that is updated to the latest MinGW version.

the code u sent, cant run in this IDE. What should I do?

1. Dump Dev-C++ and get a different IDE, if possible. Even the dinosaurs wouldn't use Dev-C++ it is so old.

2. MikeyBoy gave very good advice. Learning how to deal with problem(s) yourself instead of just saying "cant run" or "get errors" and expecting others to be mind-readers is only hurting YOU.

The Zero-th rule is "Write Your Own Code FIRST." Just dumping your assignment and expecting others to do the work for you, for free, doesn't promote learning how to program.

You show us code you've written, explain IN DETAIL problems you are having, will go a long way to being a better programmer.

And most people here will be eager to help since you've taken the time to not be a code leech.
Last edited on
There is another kind of DevCpp called wxDev-C++.
It comes with wxWidgets and a form designer.
That is even more outdated than Orwell's port. From 2012. Orwell is from 2015.
Last edited on
Yeah it is. Probably something for nostalgic guys.
Holy Dinosaur, Batman! That wxDev-C++ is only 32 bit, using MinGW-GCC 4.6.1! *OUCH!*

It reminds me of the Delphi/C++Builder IDEs. Drag-n-drop components to visually create a Windows form-based dialog/app window.
I have fond memories of using Borland C++ 4.0 (before builder!) with Windows 3.1 /95.
I have fond memories of using Turbo C and Turbo Pascal with MS DOS 5
Agreed back to MS-DOS 3 when I moved to PCs from mini-computers. Together with MASM and TASM!
win 95 was so bad I kept running dos until 98 came out.
I was mostly a borland guy, and I liked builder (easier to get a simple program going by a long way). Only microsoft I had was MASM, and I used TASM more.
Also a turbo pascal guy, though I started THAT language on a mac as an older kid, the aptly named 'mac pascal' on those things that replaced the 2e. Before that was also apple, the 2e and basic... I remember playing chess off a cassette tape on a 2e. It made the recent tournament look like bullet chess.
Last edited on
Win95 was marginally worse than Win98/98SE, but better than WinMe. That was really bad.
95 had 2 big issues. First, they undersold the requirements, and its memory leaks and memory hogging caused it to burn up hard disks with virtual memory. Always on public systems, which I was helping run at the time, were chewing up disks at costly rates. Second, it was unstable.
98 fixed both stability and VM grinding.
ME was bad -- at one point every other release was bad, 95 b, 98 b, nt3 b, nt4 g, me bad, 2000 good, and so on...
At work circa 1988 I had DOS 3 and DOS 6, but then I had UNIX, then personally Linux ever since the beginning of it in 1991 ........

But also note that windows was used for work exclusively throughout my career, because that was what the work software ran on.
I moved from using/programming DOS to Windows 3.0/3.1/3.11/wfw to 95 to NT4/2000/XP. I never had the 'pleasure' of using Win98/ME :)

I also loved Turbo Pascal and then Delphi. I used pascal extensively whilst at University and I loved the language - particularly it's data definition abilities! C++ could learn from that and implement some.
Pages: 12