cout all numbers from max to min

hi all :)
I wrote this code for take 30 numbers and cout all numbers from max to min but I don't know whats the problem





#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{
int i;
int x;
int j;
int temp;
int a[30];
int n;

for (i = 1; i < 30; i++)
{
cout << "please enter your number"<<endl;
cin >> x;
}


for (i = 0; i < 29; i++)
{
for (j = 0; j < 30; j++)
{
a[j] >= a[j + 1];
int temp = a[j + 1];
a[j + 1] = j;
a[j] = temp;

}
}
for (n = 0; n < 30; n++);
{
cout << a[n];
}
return 0;
}

cin >> x;
You never do anything with this value. Why is the user entering it?

a[j] >= a[j + 1];
This doesn't do anything

You create an array, "a", and then you never put any values into it, so it's just random values.



Its just practice to see the result

I mean from a [J]>a [j+1]
Compare the number in array a [j] with array a [j+1]
I know its not work correctly
Whats your suggestion to fix that?
Last edited on
To do something based on the results of a comparison:
1
2
3
4
if (a[j] >= a[j + 1])
{
  // do something
}


Right now, your code just says:
a[j] >= a[j + 1];
Last edited on
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{
int i;
int x;
int j;
int temp;
int a[30];
int n;
for (i = 1; i < 30; i++)
{
cout << "please enter your number" << endl;
cin >> x;
}


for (i = 0; i < 29; i++)
{
for (j = 0; j < 30; j++)
{
if (a[j] >= a[j + 1]);
{
int temp = a[j + 1];
a[j + 1] = j;
a[j] = temp;
}

}
}
for (n = 0; n < 30; n++);

{
cout << a[n];
}
return 0;

}

anyone now what this code dosent work????
What Moschops said above and some tweaks to the sort. (Bubble sort algo: http://www.cprogramming.com/tutorial/computersciencetheory/sorting1.html)

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
int main()
{
    int i;
    int x;
    int j;
    int temp;
    int a[30];
    int n;
    
    for (i = 1; i < 30; i++) // i=0; 
    {
        cout << "please enter your number" << endl;
        cin >> x; // cin >> a[i]  
    }
        
    for (i = 0; i < 29; i++) // i < 30
    {
        for (j = 0; j < 30; j++) // j < 29
        {
            if (a[j] >= a[j + 1]); // remove ; at end
            {
                int temp = a[j + 1]; 
                a[j + 1] = j;  // = a[j]
                a[j] = temp; 
            } 
        }
    }

    for (n = 0; n < 30; n++); // remove ; at end
    {
        cout << a[n];  // optional add blank space or newline between numbers
    }
    
    return 0;

}



Edit: or to sort from high to low, change if (a[j] >= a[j + 1]) to if (a[j] <= a[j + 1])
Last edited on
tnx a lot it goes one step forward and dont break but its still dont show the result and after take 30 num its close

in show out put from debug show this messages

'ConsoleApplication1.exe' (Win32): Loaded 'C:\Users\robert\Desktop\programing\4\ConsoleApplication1\Debug\ConsoleApplication1.exe'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Program Files\Bitdefender\Bitdefender 2015\active virus control\Avc3_00399_003\avcuf32.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
The program '[9944] ConsoleApplication1.exe' has exited with code 0 (0x0).
It sounds like those are informational messages. One of the answers on this Stack Overflow post suggests running the code using CTRL-F5 instead of only F5 key.

https://stackoverflow.com/questions/28381361/cannot-find-or-open-the-pdb-file-visual-studio-c-2013
Topic archived. No new replies allowed.