| | |
What is wrong?..!
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
Just because something is syntactically accurate doesn't mean "there is nothing wrong with the code." An important thing to mention about code, is that you are supposed to make it easy to read. Just because "it compiles fine" doesn't mean another programmer can look at it, and decipher your code without major effort. Some of these things include proper indentation. Indentation allows someone to see which blocks of code fall under which conditions and loops. It is meant to simplify the debugging process, and make life easier for you later on, and any other programmers who might work on your code. I'll wager that Salem's comment, wasn't merely a quick fix to a problem, it was meant to address a much deeper issue as well, such as the entirety of the style. I'll guess it should look something more like:
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <conio.h> using namespace std; int main(int argc, char **argv) { clrscr(); int a[10],n,min,max,i; cout<<"Enter the number of elements in the matrix \t"; cin>>n; cout<<"enter the elements of the matrix \n"; for(i=0;i<n;i++) { cin>>a[i]; max=min=a[0]; for(i=0;i<n;i++) { if(a[i]>max) { max=a[i]; } else if(a[i]<min) { min=a[i]; } } } cout<<"Largest is "<<max<<" and Smallest is "<<min; getch(); return 0; }
•
•
Join Date: Oct 2008
Posts: 40
Reputation:
Solved Threads: 6
What you've got works, since the if/else loop code is actually only a single statement. I would recommend, however, that you include brackets for clarity and ease of maintenance; it doesn't cost anything and it can lead to errors that can be quite difficult to identify (like the error that you originally had).
Thanx,
Sean
Thanx,
Sean
![]() |
Similar Threads
- My CD-RW plays but won't burn. What could be wrong?? Help Please? (Storage)
- Retrieve email I sent to the wrong person (Web Browsers)
- Ram voltage wrong?? (Motherboards, CPUs and RAM)
- Am I going about this the wrong way (IT Professionals' Lounge)
- wats wrong with imesh??? (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Help on fscanf
- Next Thread: Copy a Folder
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion count data database delete deploy desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






