| | |
plz tell me wherez my mistake in dis program!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 9
Reputation:
Solved Threads: 0
below is my code the whole program is for prompting user to enter 10 nos. b/w 20 to 100 it will while is there to check wheter the user entr the corect number or not, it will also check that the entered number is unique and was not previously entered by the user. at end of program simply it will display the non dublicate nos. whole program is correct but at end it is not displaying correct result. plz check the code n tell me wherz my mistake.
Code formatted and tags added. -Narue
Rose
C++ Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> #include<iostream.h> main() { int nTmp,j; //declares variable bflag th be of type bool & intializes bflag to false //bool is a data type whose value may be false or true bool bFlag=false; int a[10]; cout<<"entr 10 numbers b/w 20 and 100"<<endl; for(int i=0;i<10;i++) { cout<<"Enter Value"<<endl; cin>>nTmp; while(!bFlag) { ////Here we check first Condition // no between 20 and 100 while((nTmp<20)||(nTmp>100)) { cout<<"enter no b/w 20 and 100"<<endl; cin>>nTmp; } j=0; while(j<=i) { if(a[j++]==nTmp) { bFlag=false; } bFlag=true; } if(bFlag==true) { //save variable a[i]=nTmp; } } //again make it false bFlag=false; } cout<<" the non dublicate nos are "<<a[i]<<endl; getch(); }
Rose
•
•
Join Date: Apr 2005
Posts: 9
Reputation:
Solved Threads: 0
my prob is that i need to print only dat numbers that r not repeated.like if i entered 50, 60, 80, 90, 99, 56, 50,98, 45, 99 so here 50 and 99 are reapeating so in the output ony 8 nos that r 50, 60, 80, 90, 99, 56, 98, 45 such that the nos that r repeating should not be displayed as u observe it in output.this is not diaplyind the ouput which i want.
for(i=0;i<10;i++)
cout<<" the non dublicate nos are "<<a[i]<<endl;
rose
for(i=0;i<10;i++)
cout<<" the non dublicate nos are "<<a[i]<<endl;
rose
>whole program is correct but at end it is not displaying correct result.
Then the whole program is not correct. :rolleyes:
>#include<stdio.h>
This isn't needed.
>main()
This is illegal C++. Implicit int is not allowed, so you need to say:
>for(int i=0;i<10;i++)
This is not portable because you access i after the loop. i should be declared outside of the loop to be correct.
Compare this with what you have:
Then the whole program is not correct. :rolleyes:
>#include<stdio.h>
This isn't needed.
>main()
This is illegal C++. Implicit int is not allowed, so you need to say:
C++ Syntax (Toggle Plain Text)
int main()
This is not portable because you access i after the loop. i should be declared outside of the loop to be correct.
Compare this with what you have:
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; int main() { int nTmp,i,j; bool bFlag=false; int a[10]; cout<<"entr 10 numbers b/w 20 and 100"<<endl; for(i=0;i<10;i++) { while(!bFlag) { cout<<"Enter Value"<<endl; cin>>nTmp; ////Here we check first Condition // no between 20 and 100 while((nTmp<20)||(nTmp>100)) { cout<<"enter no b/w 20 and 100"<<endl; cin>>nTmp; } for(j=0;j<i;j++) { if(a[j]==nTmp) { cout<<nTmp<<" already exists"<<endl; break; } } if(j==i) { //save variable a[i]=nTmp; bFlag=true; } } //again make it false bFlag=false; } cout<<" the non dublicate nos are "<<endl; for(i=0;i<10;i++) cout<<a[i]<<endl; }
I'm here to prove you wrong.
![]() |
Similar Threads
- problem in output ... (Computer Science)
- need ur help in c++ coding plz help (C++)
- No sound, help! (Windows NT / 2000 / XP)
- Compiling .py files... (Python)
- int function(fstream)//illegal argument (C)
- Help with programming assignment (Python)
- How to traverse an array?? What am I doing wrong? (C++)
Other Threads in the C++ Forum
- Previous Thread: Why Data Structures???...QUESTIONS INSIDE
- Next Thread: Your Valuable Opinion Needed - Thank You
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






