Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Leda > Enumerated data...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 135 of 212
Post > Topic >>

Enumerated data type problem

by eaglesdare@[EMAIL PROTECTED] (john) Jun 15, 2004 at 11:52 AM

Hi
>  
>  I am a beginner to C++ so suffice to say my programming efforts below
> are gonna be weak but I have 2 problems for which any assistance would
> be most appreciated.
> 
> I am trying to sort the 4 values for summer,fall, winter, spring; to get
the
> highest and lowest and then display the season name and NOT the value
> for that season.  The range of values should be within 0-500.  I am not
sure how do do that with enumerated data types - at the moment I am just
getting the value for that season.
> 
> I would also like to have the code that sorts the values form part of
> a function (I am still learning about functions) could anyone give me
> advice on how to modify this code so that that the function works.
> 
> Many thanks
> 
> John
> 
> 
> #include <iostream.h>
> #include <stdlib.h>
> #include <conio.h>
> #include <string.h>
> #include <windows.h>
> 
> void gotoxy(int x, int y)
> {
> 
> HANDLE hConsoleOutput;
> COORD dwCursorPosition;
> 
> dwCursorPosition.X = x;
> dwCursorPosition.Y = y;
> hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
> SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
> 
> }
> 
> int divider1 (int);
> int divider2 (int);
> int divider3 (int);
> int divider4 (int);
> 
> int divider1 (int summ)
> {
> return (summ /= 10);
> }
> int divider2 (int fall)
> {
> return (fall /= 10);
> }
> int divider3 (int wint)
> {
> return (wint /= 10);
> }
> int divider4 (int spri)
> {
> return (spri /= 10);
> }
> 
> int main()
> {
> int summ,fall,wint,spri;
> enum seasons {Summer,fall,Winter,Spring,seasons};
> char cont;
> int min;
> int max;
> int sorter [6];
 
> do
> {
> system("CLS");
> gotoxy (1,13);
> cout << "  Please enter monies received by season when
> prompted"<<flush;
> cout << endl << endl;
> 
> system ("pause");
> 
> system("CLS");
> 
> char year[10];
> char tmpbuffer[30];
> int tmpsummer, tmpfall,tmpwinter,tmpspring;
> 
> gotoxy (3,4);
> cout << "Please ONLY insert 3 digit integers from 1 to 500 "<<endl;
> 
> gotoxy (1,9);
> 
> cout << "please enter the year "<<flush;
> cin.getline(year,sizeof(year));
> 
> gotoxy (1,12);
> do
> {
> cout << "Monies received for Summer "<<flush;
> cin.getline(tmpbuffer,sizeof(tmpbuffer));
> 
> while (atoi(tmpbuffer) == 0)
> {
> cout <<"Error : Invalid input - numerical only!"<<endl;
> cin.getline(tmpbuffer,sizeof(tmpbuffer));
> }
> tmpsummer=atoi(tmpbuffer);
> }
> while ((tmpsummer <0) || (tmpsummer >500));
> 
> gotoxy (1,16);
> do
> {
> cout << "monies received for the fall " <<flush;
> cin.getline(tmpbuffer,sizeof(tmpbuffer));
> 
> while (atoi(tmpbuffer) == 0)
> {
> cout <<"Error : Invalid input - numerical only!"<<endl;
> cin.getline(tmpbuffer,sizeof(tmpbuffer));
> }
> tmpfall=atoi(tmpbuffer);
> }
> while ((tmpfall <0) || (tmpfall >500));
> 
> gotoxy (1,20);
> do
> {
> cout << "monies received for Winter " <<flush;
> cin.getline(tmpbuffer,sizeof(tmpbuffer));
> while (atoi(tmpbuffer) == 0)
> 
> {
> cout <<"Error : Invalid input - numerical only!"<<endl;
> cin.getline(tmpbuffer,sizeof(tmpbuffer));
> }
> tmpwinter=atoi(tmpbuffer);
> }
> while ((tmpwinter <0) || (tmpwinter >500));
> gotoxy (1,24);
> do
> {
> cout << "monies received for Spring " <<flush;
> cin.getline(tmpbuffer,sizeof (tmpbuffer));
> 
> while (atoi(tmpbuffer) == 0)
> {
> cout <<"Error : Invalid input - numerical only!"<<endl;
> cin.getline(tmpbuffer,sizeof(tmpbuffer));
> }
> tmpspring=atoi(tmpbuffer);
> }
> while ((tmpspring<0) || (tmpspring >500));
> 
> int ArraySeason[seasons] = {tmpsummer,tmpfall,tmpwinter,tmpspring};
> 
> summ = ArraySeason[Summer];
> autu = ArraySeason[fall];
> wint = ArraySeason[Winter];
> spri = ArraySeason[Spring];
> cout <<endl;
> 
> system ("pause");
> system ("CLS");
> 
> summ = divider1(summ);
> fall = divider2(fall);
> wint = divider3(wint);
> spri = divider4(spri);
> 
> for (int i = 16; i<=66;i++)
> {
> gotoxy (i,20);
> cout << "_"<<flush;
> }
> 
> int p= 0;
> for (int j = 16; j<=66;j+=10)
> {
>   gotoxy (j,22);
>   cout << (p)<<flush;
>   gotoxy (j,21);
>   cout << "|"<<flush;
>   p = p +=100;
> 
> }
 
> gotoxy (7,10);
> cout <<"SUMMER"<<flush;
> gotoxy (7,13);
> cout <<"fall"<<flush;
> gotoxy (7,16);
> cout <<"WINTER"<<flush;
> gotoxy (7,19);
> cout <<"SPRING"<<flush;
> 
> int k=0;
> char label[] = "SEASON";
> for (int l = 12; l <=18;l++)
> {
> gotoxy (3,l);
> 
> cout << label[k]<<flush;
> k++; 
> }
> 
> gotoxy (16,10);
>  for (int z = 1; z <= summ;z++)
> {
> cout << "#"<<flush;
> 
> }
> cout << " " << ArraySeason[Summer]<<flush;
> gotoxy (16,13);
> for (int zz = 1; zz <= fall;zz++)
> {
> cout << "#"<<flush;
> }
> cout  << " " << ArraySeason[fall]<<flush;
> gotoxy (16,16);
> for (int zzz = 1; zzz <= wint;zzz++)
> {
> cout << "#"<<flush;
> }
> cout  << " " << ArraySeason[Winter]<<flush;
> gotoxy (16,19);
> for (int zzzz = 1; zzzz <= spri;zzzz++)
> {
> cout << "#"<<flush;
> }
> cout  << " " << ArraySeason[Spring]<<flush;
> 
> sorter [0]=tmpsummer;
> sorter [1]=tmpfall;
> sorter [2]=tmpwinter;
> sorter [3]=tmpspring;
> 
> min=max=sorter[0];
> for (i=0;i<4;i++)
> {
>         if (sorter[i]<min) min=sorter[i];
>         if (sorter[i]>max) max=sorter[i];
> }
> gotoxy (1,30);
> cout << "The best season was "<<max<<endl;
> gotoxy (1,32);
> cout << "The worst season was "<<min<<endl;
> 
> cout << "Continue (y/n)";
> cin >> cont;
> 
> gotoxy (1,80);
> cout << flush <<endl;
> 
> } while (cont == 'y' || cont == 'Y');
>  
> system ("CLS");
> 
> return 0;
> }
>




 1 Posts in Topic:
Enumerated data type problem
eaglesdare@[EMAIL PROTECT  2004-06-15 11:52:22 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 3:31:46 CDT 2008.