I need the program to have 3 options. Choose how many #'s to enter, and display the largest # input; enter #'s until -99 is input then end program and display smallest # entered; or quit the program. I have a large part of the program written but it's not working properly and I am pretty new to programming. Can someone just help me get the code for the first part straightened out then maybe I can figure it out from there. Here is what I have:
#include %26lt;iostream%26gt;
using namespace std;
const int SENTINEL = -99; //to end option 'B'
int number; //variable to store #s
int counter;
char limit; //variable to store amount of #s to input in 'A'
int main()
{char sel;
number = 0;
int count = 0;
do{
cout %26lt;%26lt; "A) Find the largest # in a list." %26lt;%26lt; endl;
cout %26lt;%26lt; "B) Find the smallest # in a list." %26lt;%26lt; endl;
cout %26lt;%26lt; "C) Quit." %26lt;%26lt; endl;
cout %26lt;%26lt; "What do you want to do?" %26lt;%26lt; endl;
cin %26gt;%26gt; sel;
switch (sel)
{case 'A':
case 'a':
cout %26lt;%26lt; "Enter the amount of numbers to input in series: ";
Can someone help me with C++ programming?
cin %26gt;%26gt; limit;
limit needs to be converted from an ascii letter '3' to an integer.
trick could be limit = limit - '0'
or do it the proper way
Reply:instead of initializing count to 0, initialize it to 1. now count will start at 1. or you could put the count++ before your cout statement.
the other person could be right about limit being in ASCII. set a breakpoint after the cin %26gt;%26gt; limit; line, and see what value you have in limit. if its 0x30 - 0x39 when you enter a 0 - 9 then its ASCII. you could make your while statement read:
while (count %26lt;= (limit %26amp; 0x0f). of course if you enter a larger number than 9, this wont work.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment