Hello goshko2,
Here is your program with a few fixes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <iostream>
#include <stdlib.h> // Not needed, but OK if you leave.
#include <conio.h> // Not needed and not everyone can use.
using namespace std; // Best not to use.
int main()
{
float suma = 0.0;
float sredno_aritmetichno = 0.0;
int broi_nulevi_chisla = 0;
float min, max;
float P[N];
int i;
int izbor;
int imax;
clrscr();
textbackground(WHITE);
textcolor(BLUE);
do
{
cin >> "nn Vavedete broi chisla <=25";
cout << "%d", &nt;
} while (nt < 1 || nt>25);
cin >> "nn Vavedete stoinosti za chislata ot masiva %d n", nt;
for (i = 0; i < nt; i++)
do
{
cin >> "b N[%d] = ", i + 1;
cout << "%p", &P[i];
} while (P[i] < -1000 || P[1]>1000);
min = 50.0;
max = -50.0;
for (i = 0; i < nt; i++)
{
if (P[i] < 0 || F[i]>0) suma += P[i];
else broi_nulevi_chisla++;
if (P[i] < min) minP = [i];
if (P[i] > max) maxP = [i];
if (P[i > max]) { max = P[i]; imax = i + 1; }
if (P[i] >= min && P[i] <= max) { suma = suma + P[i]; nt++; }
sredno_aritmetichno = suma / nt;
do
{
clrscr();
puts("n");
puts(" Menu: ");
puts(" 1. Izchislqvane na sredno arimetichno na chislata v intervala (min,max) ");
puts(" 2. Izchislqvane na sumata ot razlichnite ot nula chisla i broq na nulevite chisla");
puts(" 3.Namirane na maksimalno polojitelno i negoviq poreden nomer");
puts(" 4. Izhod");
}
do
{
cin >> ("nt Vashiqt izbor: ");
cout << ("%d", &izbor);
} while (izbor < 1 || izbor>4);
}
|
I did put a few comment in the program for now, but what I want you to see is the layout of the code. With proper indenting and use of the {}s , as I have changed, you can easily see that the opening brace of main has no closing brace. When the {}s line up in the same column the {}s are easier to match. I am not saying that there is anything wrong with what you did it works, but what is above is easier to follow.
I will mention this early "conio.h" is an old header file that is no longer used by other IDEs/compilers. This tends to limit your code to your computer.
A "float" is OK, but not as accurate as a "double" and these days a "double is the preferred floating point type.
Some variables are initialized, but some are not. My personal preference is to initialize a variable when it is defined just to know that it does not contain a garbage value. Some variables the get a value quickly and do not need to be initialized.
From C++11 on you can define and initialize a variable as:
int izbor{};
. The empty {} will set the variable to zero.
Line 13. This is not allowed in C or C++. The "N" needs to be a constant number to define an array. And at this point "N" is not even defined.
Lines 17 - 19. Lead me to believe that you may be using a very old IDE/compiler as these functions are not available in C++.
Line 23. Will not work for input.
Line 24. You are mixing C++ and C code in the same line and that does not work. It should look more like:
cout << nt;
. Except that "nt" is an undefined variable.
Not sure if you realize it, but line 29 starts a for loop and line 30 is the only part of the for loop. Lines 36 on, although indented, are not part of the for loop. I suspect this indenting is because of the missing closing brace of "main".
After that there are some syntax errors, some from mixing C and C++ code the wrong way, undefined variables and misspelled variables.
I have not gone over all of the code yet to see all that needs fixed just some of the big things that I saw.
Hope that helps,
Andy