How do i change the input?

This is a discussion on How do i change the input? within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> #include <conio.h> int main() { double meannumbers; double totalmeannumbers = 0; double totalamountofnumbers = 0; double holder=100; ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    8

    How do i change the input?

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
    
    	double meannumbers;
    	double totalmeannumbers = 0;
    	double totalamountofnumbers = 0;
    	double holder=100;
    	double lowest;
    
    	clrscr();
    	cout << "Enter your first test score\n" <<endl;
    	cin>>meannumbers;
    	holder = meannumbers;
    
    	while (meannumbers !=-1)
    	{
    		totalmeannumbers = totalmeannumbers + meannumbers;
    		totalamountofnumbers ++;
    
    		cout << "Enter your next test score or enter -1 to quit."<<endl;
    		cin >> meannumbers;
    		if (meannumbers <= holder && meannumbers >=0)
    		{
    			holder = meannumbers;
    
    		}
    
    	}
    
    	cout<< "The average of the numbers is " << (totalmeannumbers-holder)/(totalamountofnumbers-1);
    	getch();
    	return 0;
    }
    i wanna make the input as "q" instead of "-1". When i do while (meannumbers !='q'), it just leads me to an infinite loop? BTW this code works perfectly i just wanna change the terminating input to q instead of -1

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,793
    Read into a string instead, then parse the string into a double if it is not equal to "q". You may need to rework your current loop logic a little too.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-24-2009, 01:28 AM
  2. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 03:13 PM
  3. Unexpected change of input values
    By imrahaseen in forum C Programming
    Replies: 6
    Last Post: 06-22-2007, 02:25 AM
  4. REQ: Change Audio Input Device?
    By DeepBlackMagic in forum Windows Programming
    Replies: 0
    Last Post: 09-01-2006, 01:24 PM
  5. Replies: 2
    Last Post: 11-08-2002, 02:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21