compiler giving me problem

This is a discussion on compiler giving me problem within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream> using namespace std; int main() { //Variables short count = 0; short average = 0; short num = ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Location
    Toronto<3 can a duh
    Posts
    5

    compiler giving me problem

    Code:
    #include<iostream>
    
    using namespace std;
    
    int main()
    {
    	//Variables
    	short count = 0;
    	short average = 0;
    	short num = 0;
    	short sum = 0;
    	char reply = ' ';
    
    	while (reply == 'Y' || reply == 'y')
    	{
    		cout<<"Enter Number";
    		cin>>num;
    		sum= sum + num;
    		count++;
    
    		cout<<"Continue";
    		cin>>reply;
    	}
    
    	average = sum/count;
    
    	cout<<sum<<endl;
    	cout<<average<<endl;
    
    	return 0;
    very simple program,but my computer wont run it!

    gives a debug problem

  2. #2
    Registered User
    Join Date
    Mar 2010
    Location
    Toronto<3 can a duh
    Posts
    5
    never mind ..char reply needs to be

    char reply = 'y';


    duh!!

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,296
    That's not the right solution. When a loop is always supposed to run at least once, you are supposed to use a do..while loop. That would also have meant that this problem would never have occurred.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler problem
    By Necrofear in forum C++ Programming
    Replies: 5
    Last Post: 01-28-2006, 10:52 AM
  2. compiler problem
    By sofarsoclose in forum C Programming
    Replies: 3
    Last Post: 07-10-2003, 11:39 AM
  3. problem solving compiler errors
    By Jan79 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2003, 10:59 AM
  4. Problem with compiler
    By knight543 in forum C++ Programming
    Replies: 4
    Last Post: 02-09-2002, 08:16 PM
  5. Please help me with this compiler problem
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2002, 04:14 PM

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