0
#include<iostream>
#include<conio.h>
using namespace std;
int n[10],i,ns;
string c;
main(){
        for(i=0;i<10;i++){   
                         cout<<"Enter a number:";
                     
        cin>>n[i];
                         }
       cout<<"Number to search:";
       cin>>ns;
       n[i]=0;
       for(n[i]=0;n[i]<10;n[i]++){
                         if(ns==n[i]){
                                      cout<<"Searched Number is Found!";
                                      }
                         else{
                                      cout<<"Searched Number is Lost!";
                                      }}
                                
                                      
                                      getch();
                                      return 0;
                                      }

help pls the output is repeating...

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
0

line 6: its int main(). c++ does not allow default function return types.

lines 4 and 5. Move those down so that they are within main() and not global variables. Globals are bad and can normally be avoided.

line 10: Entering numeric data types such as integers leaves the '\n' <Enter> key in the keyboard buffer which causes problems. You have to flush it out, like this: cin.ignore(); Here is a more detailed explanation how to flush the input buffer.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.