hey every one

please can u help me .. i need this today

Write a C++ program to read numbers end with -1 then print the largest number

i'm tring but always print to me the largest -1 that's wrong! :"(

how can i fix this

#include <iostream>

int main()
{
  int number;
  int count;
  int largest;

   
  count = 0;
  while ( number != -1)
 {
  std::cout << "Enter the number: ";
  std::cin >> number;		
  largest = number;
	  if ( number > largest && number!= -1 ); 
		  largest = number;
	count = count + 1;	


	}
  
  
  std::cout << "The largest number is : " << largest << std::endl;

 return 0; 

 }

i wanna out put to be show like this .. i input n numbers and read the largest

Enter the number: 3
Enter the number: 5
Enter the number: 8
Enter the number: -1

The largest number is 8

please help meeee

..

1. Delete line 15.

2. Delete the semicolon at the end of line 16

3. No need for variable count so delete it on lines 6, 10 and 18.

4. initialize value of number to 0 on line 5 because its used on line 11.

1. Delete line 15.

2. Delete the semicolon at the end of line 16

3. No need for variable count so delete it on lines 6, 10 and 18.

4. initialize value of number to 0 on line 5 because its used on line 11.

thanxxx alooot Ancient Dragon u r the best it works with me :)

But remember that it only works for positive numbers. Enter all negative numbers and it doesn't work because of the initial value of number

But remember that it only works for positive numbers. Enter all negative numbers and it doesn't work because of the initial value of number

really thanxx alot 4 remember me about it .. when the program worked i'm happy and forget the negative numbers lol .. but i've edit it .. :)

#include <iostream>

int main()
{
  int number ;
  int largest;

  while ( number != -1)
 {
  std::cout << "Enter the number: ";
  std::cin >> number;		
  
	  if ( number > largest && number!= -1 )
		  largest = number;	
	}
  
  std::cout << "The largest number is : " << largest << std::endl;

 return 0; 

 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.