Friday, July 31, 2009

Basic C++ Programming Help?

My program is setup so u can restart the program by not pressing 'x'. When I restart the program, my previous results carry on. How do I reset the results each time I run the program? Please post what the code looks like. Thanks.





int counter = 0;


int oddcount = 0;


int num1 = 0;


int scores = 0;


char letter;


int highestscore = 0;





do


{


cout%26lt;%26lt;"How many scores are you entering?"%26lt;%26lt;endl;


cin%26gt;%26gt;num1;








for (int counter=0; counter%26lt;num1;counter++)


{





cout%26lt;%26lt;"Enter an integer: "; cin%26gt;%26gt;scores;





cout%26lt;%26lt;endl;








oddcount += (( scores % 2)!= 0);





if ( scores %26gt; highestscore )





highestscore = scores;


}


cout%26lt;%26lt;"You entered "%26lt;%26lt;oddcount%26lt;%26lt;" odd numbers."%26lt;%26lt;endl;


cout%26lt;%26lt;"The highest # is "%26lt;%26lt;highestscore%26lt;%26lt;endl;


cout%26lt;%26lt;"Finish...press 'x' to exit program. any other key to run again."%26lt;%26lt;endl;


cin%26gt;%26gt;letter;


}


while (letter != 'x');

Basic C++ Programming Help?
do


{


oddcount = 0


highestscore = 0


cout%26lt;%26lt;"How many scores are you entering?"%26lt;%26lt;endl;
Reply:do


{


int counter = 0;


int oddcount = 0;


int num1 = 0;


int scores = 0;


char letter;


int highestscore = 0;





cout%26lt;%26lt;"How many scores are you entering?"%26lt;%26lt;endl;


cin%26gt;%26gt;num1;








for (int counter=0; counter%26lt;num1;counter++)


{





cout%26lt;%26lt;"Enter an integer: "; cin%26gt;%26gt;scores;





cout%26lt;%26lt;endl;








oddcount += (( scores % 2)!= 0);





if ( scores %26gt; highestscore )





highestscore = scores;


}


cout%26lt;%26lt;"You entered "%26lt;%26lt;oddcount%26lt;%26lt;" odd numbers."%26lt;%26lt;endl;


cout%26lt;%26lt;"The highest # is "%26lt;%26lt;highestscore%26lt;%26lt;endl;


cout%26lt;%26lt;"Finish...press 'x' to exit program. any other key to run again."%26lt;%26lt;endl;


cin%26gt;%26gt;letter;


}


while (letter != 'x');


No comments:

Post a Comment