English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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
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 << "A) Find the largest # in a list." << endl;
cout << "B) Find the smallest # in a list." << endl;
cout << "C) Quit." << endl;
cout << "What do you want to do?" << endl;
cin >> sel;
switch (sel)
{case 'A':
case 'a':
cout << "Enter the amount of numbers to input in series: ";

2006-11-12 08:36:48 · 2 answers · asked by lparker_2005 2 in Computers & Internet Programming & Design

here's the rest of it

cin >> limit;

while (count <= limit)
{
cout << "Enter the " << count << " number: ";
count++;
cin >> number;
}
break;
case 'B':
case 'b':
while (number != SENTINEL)
{
cout << "Enter as many numbers as you like. When you are finished enter "
<< SENTINEL << "." << endl;
cin >> count >> number;
}
break;
case 'C':
case 'c':
break;
default:
cout << "Invalid Input." << endl;
break;
}
}
while (sel != 'c' || sel != 'C');

return 0;
}



Thanks for any help!!

2006-11-12 08:38:36 · update #1

A couple of the problems I have with this program is in option A when I enter the amount of numbers I want to include it starts the count as 0 instead of 1. It also doesn't stop when I reach the number I entered. I am not sure how to correct this.

2006-11-12 08:42:54 · update #2

2 answers

cin >> 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

2006-11-12 08:59:02 · answer #1 · answered by Mn 6 · 0 1

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 >> 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 <= (limit & 0x0f). of course if you enter a larger number than 9, this wont work.

2006-11-13 09:29:28 · answer #2 · answered by justme 7 · 0 0

fedest.com, questions and answers