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

I have been taking a programming course for a few weeks now and need a little help with an assignment. My assignment is to write a program that displays a menu with the the option to find the largest # with a known quantity of numbers; find the smallest # with an unknown quantity of numbers or quit.

Here is what I have so far, but my book has gotten me so confused. I need some pointers as to what I am missing or what is wrong and needs fixed. Any help would be greatly appreciated.
Serious answers only please.

#include
using namespace std;
const int SENTINEL = -99; //to end option 'B'
int number; //variable to store numbers
int counter;
char limit; //variable to store amount of numbers to input in 'A'

int main()
{
char sel;
number = 0;
int count = 0;

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)

2006-11-11 06:25:17 · 5 answers · asked by lparker_2005 2 in Computers & Internet Programming & Design

{
case 'A':
case 'a':
cout << "Enter the amount of numbers to input in series: ";
cin >> limit;

while (counter < 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;
}
return 0;
}

2006-11-11 06:27:02 · update #1

We haven't learned about arrays yet. Just basic loop structures.

2006-11-11 07:04:46 · update #2

5 answers

You would be better off going to www.homework.com or to www.studybuddy.com There is a lot of help there.

2006-11-11 06:33:17 · answer #1 · answered by ruth4526 7 · 0 2

You're overwriting the previously entered number every time you cin a number from the list.

You need to set up an array, say
int list[100];

Then use an integer variable to count your position in the array
int i;
cout << "Enter the numbers for the list: "
while(i=0;i < listsize;i++)
cin >> list[i];

The better way to do this is to use a linked list since there is then no upper bound on the size of the list of numbers, but that is probably a bit too high level for an early programming class. I'd stick with the array solution.

2006-11-11 06:32:40 · answer #2 · answered by Anonymous · 0 0

well, first, your program will only run through 1 selection then end. you need to make a loop with your selections in it. something like:
do
{
//your selections
//your code
}
while (sel != 'c' || sel != 'C');

next, in your "case 'A'" you never initialize counter or increment it. did you mean to use count instead?

in your "case 'B'" you never increment count, and all it does is read in numbers. I assume you just didnt finish it yet because your still trying to get case a to work first.

thats for starters just off the top of my head

2006-11-12 01:30:05 · answer #3 · answered by justme 7 · 0 0

not anymore, at one time C++ become merely an extension of C. through fact then, C has replaced, and so has C++. even with the undeniable fact that that being reported that is common for an identical software to collect the two C and C++. the approach is an identical, yet there are in basic terms some alterations int he libraries which you like the compiler to link to.

2016-11-23 15:51:05 · answer #4 · answered by Anonymous · 0 0

#include
#include
using namespace std;
int main(){
int i,min_val,max_val;
int list[10];
for(i=0;i<10;i++) list[i]=rand();
min_val=list[0];
for(i=1;i<10;i++)
if(min_val>list[i]) min_val=list[i]
cout<<"minimun value: "< max_val=list[0];
for(i=1;i<10;i++)
if(max_val max_val=list[i];
cout< return 0;
}

2006-11-11 06:43:34 · answer #5 · answered by Haruhi 1 · 0 1

fedest.com, questions and answers