Having few errors in the code

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

41 Replies - 1593 Views - Last Post: 13 January 2013 - 04:04 PM Rate Topic: ***-- 2 Votes

#16 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,510
  • Joined: 12-December 12

Re: Having few errors in the code

Posted 13 January 2013 - 09:52 AM

int detsember;

This will have a default value of 0. You could re-instate the code you had earlier, which set detsember = 12. Better would be to look into arrays, but perhaps you intend to move on to them later.
Was This Post Helpful? 0
  • +
  • -

#17 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having few errors in the code

Posted 13 January 2013 - 10:22 AM

View Postandrewsw, on 13 January 2013 - 09:52 AM, said:

int detsember;

This will have a default value of 0. You could re-instate the code you had earlier, which set detsember = 12. Better would be to look into arrays, but perhaps you intend to move on to them later.

I think that is the next topic on which the future test will be based.I will try to apply your idea now.

Tried your idea
#include <iostream>
#include <iomanip> 
#include <conio.h>

/* kt3 y3_2 */   
/* programm "Aastaaeg" */ 


using namespace std;

int main()
{





int K;  /* Month K  */ 
int A;  /* Season A */
int  jaanuar;
int  veebruar;
int  marts; 
int  aprill;
int  mai; 
int  juuni;
int  juuli;
int  august;
int  september; 
int  oktoober;
int  november;
int  detsember;


cout<<"Sisestage kuu: ";                /* Asks for month*/
  cin>>K; 
                            /* The input K is put in lower cased month name*/ 
  jaanuar = 1;                      /* Giving the value to months to use it to determine season */
  veebruar = 2; 
  marts = 3; 
  aprill = 4; 
  mai = 5; 
  juuni = 6; 
  juuli = 7; 
  august = 8; 
  september = 9; 
  oktoober = 10; 
  november = 11; 
  detsember = 12;
  

  if  (K==12) 
  {                  
     cout<<"Kuu "<< "detsember"<<" aastaaeg on talv.\n"; /*Result when the season is winter*/
  } 
  
  else if  (K==1)
  {           
     cout<<"Kuu"<<"jaanuar"<<" aastaaeg on talv.\n";           /*Result when the season is spring*/   
  } 
    else if  (K==2)
  {           
     cout<<"Kuu"<<"veebruar"<<" aastaaeg on talv.\n";           /*Result when the season is spring*/  
  }
       else if ( K==3 ) 
  {            // I use else just to show an example 
     cout<<"Kuu"<<"marts"<<" aastaaeg on kevad.\n";           /*Result when the season is spring*/
  } 
        else if ( K==4) 
  {            // I use else just to show an example 
     cout<<"Kuu"<<"aprill"<<" aastaaeg on kevad.\n";           /*Result when the season is spring*/
  }  
        else if ( K==5) 
  {            // I use else just to show an example 
     cout<<"Kuu"<<"mai"<<" aastaaeg on kevad.\n";           /*Result when the season is spring*/
  } 
  
  else if  (K==6)
  {             
     cout<<"Kuu"<<"juuni"<<" aastaaeg on suvi.\n";          /*Result when the season is summer*/
  } 
 else if  (K==7)
  {             
     cout<<"Kuu"<<"juuli"<<" aastaaeg on suvi.\n";          /*Result when the season is summer*/
  }  
   else if  (K==8)
  {             
     cout<<"Kuu"<<"august"<<" aastaaeg on suvi.\n";          /*Result when the season is summer*/
  } 
  else if  (K==9)
  {
    cout<<"Kuu"<<"september"<<" aastaaeg on sügis.\n";     /*Result when the season is autumn*/  
  }  
   else if  (K==10)
  {
    cout<<"Kuu"<<"oktoober"<<" aastaaeg on sügis.\n";     /*Result when the season is autumn*/  
  }   
   else if  (K==11)
  {
    cout<<"Kuu"<<"november"<<" aastaaeg on sügis.\n";     /*Result when the season is autumn*/  
        
}  else  {
    cout<<" Sisestasite kuu nime valesti.Palun proovige uuesti.\n";  
}  
getch();
return 0; 
} 



This works only if I insert the number of month(e.g. december=12 , so if I insert 12 , it gives me the correct season , but I still need it to work when I insert december , I get the season clause.

Tried another idea
#include <iostream>
#include <iomanip> 
#include <conio.h>

/* kt3 y3_2 */   
/* programm "Aastaaeg" */ 


using namespace std;

int main()
{





int K;  /* Month K  */ 
int A;  /* Season A */
int  jaanuar;
int  veebruar;
int  marts; 
int  aprill;
int  mai; 
int  juuni;
int  juuli;
int  august;
int  september; 
int  oktoober;
int  november;
int  detsember;


cout<<"Sisestage kuu: ";                /* Asks for month*/
  cin>>K; 
  K==("jaanuar" || "veebruar" || "marts" || "aprill" || "marts" || "mai" || "juuni" || "juuni" || "juuli" || "august" || "september" || "oktoober" || "november" || "detsember");                         /* The input K is put in lower cased month name*/ 

  

  if  (K==detsember) 
  {                  
     cout<<"Kuu "<< " detsember"<<" aastaaeg on talv.\n"; /*Result when the season is winter*/
  } 
  
  else if  (K=jaanuar)
  {           
     cout<<"Kuu"<<" jaanuar"<<" aastaaeg on talv.\n";           /*Result when the season is spring*/   
  } 
    else if  (K==veebruar)
  {           
     cout<<"Kuu"<<"veebruar"<<" aastaaeg on talv.\n";           /*Result when the season is spring*/  
  }
       else if ( K==marts ) 
  {            // I use else just to show an example 
     cout<<"Kuu"<<" marts"<<" aastaaeg on kevad.\n";           /*Result when the season is spring*/
  } 
        else if ( K==aprill) 
  {            // I use else just to show an example 
     cout<<"Kuu"<<" aprill"<<" aastaaeg on kevad.\n";           /*Result when the season is spring*/
  }  
        else if ( K==mai) 
  {            // I use else just to show an example 
     cout<<"Kuu"<<" mai"<<" aastaaeg on kevad.\n";           /*Result when the season is spring*/
  } 
  
  else if  (K==juuni)
  {             
     cout<<"Kuu"<<" juuni"<<" aastaaeg on suvi.\n";          /*Result when the season is summer*/
  } 
 else if  (K==juuli)
  {             
     cout<<"Kuu"<<"juuli"<<" aastaaeg on suvi.\n";          /*Result when the season is summer*/
  }  
   else if  (K==august)
  {             
     cout<<"Kuu"<<"august"<<" aastaaeg on suvi.\n";          /*Result when the season is summer*/
  } 
  else if  (K==september)
  {
    cout<<"Kuu"<<"september"<<" aastaaeg on sügis.\n";     /*Result when the season is autumn*/  
  }  
   else if  (K==oktoober)
  {
    cout<<"Kuu"<<"oktoober"<<" aastaaeg on sügis.\n";     /*Result when the season is autumn*/  
  }   
   else if  (K==november)
  {
    cout<<"Kuu"<<"november"<<" aastaaeg on sügis.\n";     /*Result when the season is autumn*/  
        
}  else  {
    cout<<" Sisestasite kuu nime valesti.Palun proovige uuesti.\n";  
}  
getch();
return 0; 
} 



This only gives the result as the clause of january.
Was This Post Helpful? 0
  • +
  • -

#18 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,510
  • Joined: 12-December 12

Re: Having few errors in the code

Posted 13 January 2013 - 10:32 AM

I think you need to spend some time studying the basics; you seem to be just guessing.
Was This Post Helpful? 0
  • +
  • -

#19 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having few errors in the code

Posted 13 January 2013 - 10:37 AM

View Postandrewsw, on 13 January 2013 - 10:32 AM, said:

I think you need to spend some time studying the basics; you seem to be just guessing.

Deadline hits tomorrow, so that time I do not have right now....
If you're not willing to lend me a hand, could you give me a link of post to help find the error of my ways.
Was This Post Helpful? 0
  • +
  • -

#20 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3623
  • View blog
  • Posts: 12,510
  • Joined: 12-December 12

Re: Having few errors in the code

Posted 13 January 2013 - 10:56 AM

http://www.dreaminco...m/134-c-basics/
Was This Post Helpful? 0
  • +
  • -

#21 jimblumberg  Icon User is offline

  • member icon


Reputation: 4142
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 11:07 AM

View Postandrewsw, on 13 January 2013 - 10:52 AM, said:

int detsember;

This will have a default value of 0. You could re-instate the code you had earlier, which set detsember = 12. Better would be to look into arrays, but perhaps you intend to move on to them later.

No this will produce an undefined value, usually not zero. An array would also need to be initialized to the proper values. This may be a good place to use enum. Also using a switch statement instead of the if/else clauses might make your program easier to read/understand.

Jim

This post has been edited by jimblumberg: 13 January 2013 - 11:09 AM

Was This Post Helpful? 2
  • +
  • -

#22 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having few errors in the code

Posted 13 January 2013 - 11:12 AM

Aftermath:After wasting numerous hours trying to enhance my code by your replies, I have learned nothing and am still in trouble.I really hoped I would be provided with the exact links giving me some sort of correct examples or feedback why is the way of my code wrong or why would this kind of code be bad and is non-functional,so I could actually learn in the process, rather than getting hissed at and said that I should really go learn the basics after messing around for 6 hours,because you know, you are bad and your code is bad.

Wow, thanks Jim.I think this might be the link I was looking for.
Was This Post Helpful? 0
  • +
  • -

#23 jimblumberg  Icon User is offline

  • member icon


Reputation: 4142
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 11:25 AM

Also the following line:
  K==("jaanuar" || "veebruar" || "marts" || "aprill" || "marts" || "mai" || "juuni" || "juuni" || "juuli" || "august" || "september" || "oktoober" || "november" || "detsember");                         /* The input K is put in lower cased month name*/ 


Is not actually doing anything. If you want to compare K to some variables you need to use an if() statement for the comparison and then actualy use the result of that comparison for something.


Jim
Was This Post Helpful? 1
  • +
  • -

#24 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having few errors in the code

Posted 13 January 2013 - 11:45 AM

#include <iostream> 
#include <iomanip> 
using namespace std;

 int main()
{   

   enum
   {
      jaanuar, veebruar, marts, aprill, mai, juuni, juuli, august, september, oktoober, november, detsember
   } K;
cout<<"Sisestage kuu: ";               /* Asks for month*/
cin>> K;   
   

   if(K == jaanuar || K == veebruar || K == detsember)
      cout << K << "aastaaeg on talv" << endl;
   else if(K == oktoober)
      cout << K <<"aastaaeg on sugis" << endl;
}

I am trying to insert the question of motninto the program to get the variable, but it gives me error like this::/programs/c/include/c++/3.4.2/bits/istream.tcc:87: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>&(*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:93: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>&(*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:102: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base&(*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:111: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:133: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:164: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:186: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:217: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:239: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:261: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:284: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:306: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:329: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:351: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:373: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:395: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/bits/istream.tcc:417: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/istream:646: note: std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char&) [with _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/istream:651: note: std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char&) [with _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/istream:687: note: std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, unsigned char*) [with _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/istream:692: note: std::basic_istream<char, _Traits>& std::operator>>(std::basic_istream<char, _Traits>&, signed char*) [with _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/iomanip:74: note: std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Resetiosflags) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/iomanip:108: note: std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setiosflags) [with _CharT = char, _Traits = std::char_traits<char>]

C:/programs/c/include/c++/3.4.2/iomanip:143: note: std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setbase) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/iomanip:219: note: std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setprecision) [with _CharT = char, _Traits = std::char_traits<char>]
C:/programs/c/include/c++/3.4.2/iomanip:253: note: std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::_Setw) [with _CharT = char, _Traits = std::char_traits<char>].
I understand that you cannot use the simple cin >> K , but need to use one of the options stated above.But which one should I use and why?

EDIT: Question of month into the program

EDIT:Question of month into the program
Was This Post Helpful? 0
  • +
  • -

#25 jimblumberg  Icon User is offline

  • member icon


Reputation: 4142
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 12:11 PM

You're close try something like:
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int K;
    enum
    {
        jaanuar, veebruar, marts, aprill, mai, juuni, juuli, august, september, oktoober, november, detsember
    } Months;
    cout<<"Sisestage kuu: ";               /* Asks for month*/
    cin>> K;


    if(K == jaanuar || K == veebruar || K == detsember)
        cout << K << "aastaaeg on talv" << endl;
    else if(K == oktoober)
        cout << K <<"aastaaeg on sugis" << endl;
}



You want to use a separate variable for your input not your enum type.

Jim
Was This Post Helpful? 1
  • +
  • -

#26 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having few errors in the code

Posted 13 January 2013 - 12:18 PM

#include <iostream>
#include <iomanip> 
#include <string> 
#include <conio.h>

/* kt3 y3_2 */   
/* programm "Aastaaeg" */ 


using namespace std;

main()
{







  enum 
{ 
jaanuar,
veebruar,
marts,
aprill,
mai, 
juuni, 
juuli, 
august,
september, 
oktoober,
november,
detsember,
} K; 
cout<<"Sisestage kuu: ";               /* Asks for month*/
cin>>K ;  
   
  jaanuar == 1;                      /* Giving the value to months to use it to determine season */
  veebruar == 2; 
  marts == 3; 
  aprill == 4; 
  mai == 5; 
  juuni == 6; 
  juuli == 7; 
  august == 8; 
  september == 9; 
  oktoober == 10; 
  november == 11; 
  detsember == 12;
  if ( (K==12) || (K==1) || (K==2))  
  {                  
     cout<<K<<" Aastaaeg on talv.\n"; /*Result when the season is winter*/
  } 
  
  else if (( K==3 )||(K==4) ||(K==5)) 
  {            // I use else just to show an example 
     cout<<K<<" Aastaaeg on kevad.\n";           /*Result when the season is spring*/
  } 
  
  else if  ((K==6) || (K==7) || (K==8))  
  {             
     cout<<K<<" Aastaaeg on suvi.\n";          /*Result when the season is summer*/
  } 
  
  else if  ((K==9) || (K==10) || (K==11))
  {
    cout<<K<<" Aastaaeg on sügis.\n";     /*Result when the season is autumn*/ 
}  else  {
    cout<<K<<" Sisestasite kuu nime valesti.Palun proovige uuesti.\n";  
 


}  
getch();
return 0; 
} 



Adapted the original code to enum, but I cannot still understand what to do with cin>>K
Was This Post Helpful? 0
  • +
  • -

#27 jimblumberg  Icon User is offline

  • member icon


Reputation: 4142
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 12:32 PM

First do you realize when you create an enum like:
enum {jaanuar,veebruar} Months;

That jaanuar has a value of zero and veebruar has a value of 1. If you want jaanuar to contain a value of 1 then you delcare the enum like:
enum {jaanuar=1,veebruar} Months;

Now jaanuar has a value of 1 and veebruar has a value of 2.

This means that you don't need the following.
   
  jaanuar == 1;                      /* Giving the value to months to use it to determine season */
  veebruar == 2; 
  marts == 3; 
  aprill == 4; 
  mai == 5; 
  juuni == 6; 
  juuli == 7; 
  august == 8; 
  september == 9; 
  oktoober == 10; 
  november == 11; 
  detsember == 12;


And instead of all the constants in your if statements you would do something like:
  if ( (K==detsember) || (K==jaanuar) || (K==veebruar))  
  {                  
     cout<<K<<" Aastaaeg on talv.\n"; /*Result when the season is winter*/
  } 


You use the enumerated values in your if statements instead of the constants.


Jim
Was This Post Helpful? 1
  • +
  • -

#28 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having few errors in the code

Posted 13 January 2013 - 12:36 PM

#include <iostream> 
#include <iomanip> 
#include <conio.h> 
using namespace std;

 int main()
{   
int K;
   enum
   {
      jaanuar, veebruar, marts, aprill, mai, juuni, juuli, august, september, oktoober, november, detsember
   } Kuud;
cout<<"Sisestage kuu: ";               /* Asks for month*/
cin>> K;   
   

   if(K == jaanuar || K == veebruar || K == detsember)
      cout << K << "aastaaeg on talv" << endl;
   else if(K == oktoober || K == september || K == november)
      cout << K <<"aastaaeg on sugis" << endl; 
         else if(K == august || K == juuli || K == juuni)
      cout << K <<"aastaaeg on suvi" << endl;   
        else if(K == marts || K == aprill || K == mai)
      cout << K <<"aastaaeg on kevad" << endl;  
 
getch();
return 0;   
}

I can insert the month, but the cout clause doesnt come right after the insertion of the month.
Was This Post Helpful? 0
  • +
  • -

#29 needhelpest  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 12-January 13

Re: Having few errors in the code

Posted 13 January 2013 - 12:57 PM

View Postjimblumberg, on 13 January 2013 - 12:32 PM, said:

First do you realize when you create an enum like:
enum {jaanuar,veebruar} Months;

That jaanuar has a value of zero and veebruar has a value of 1. If you want jaanuar to contain a value of 1 then you delcare the enum like:
enum {jaanuar=1,veebruar} Months;

Now jaanuar has a value of 1 and veebruar has a value of 2.

This means that you don't need the following.
   
  jaanuar == 1;                      /* Giving the value to months to use it to determine season */
  veebruar == 2; 
  marts == 3; 
  aprill == 4; 
  mai == 5; 
  juuni == 6; 
  juuli == 7; 
  august == 8; 
  september == 9; 
  oktoober == 10; 
  november == 11; 
  detsember == 12;


And instead of all the constants in your if statements you would do something like:
  if ( (K==detsember) || (K==jaanuar) || (K==veebruar))  
  {                  
     cout<<K<<" Aastaaeg on talv.\n"; /*Result when the season is winter*/
  } 


You use the enumerated values in your if statements instead of the constants.


Jim

I didnt not realize that enum=enumarated.:/
#include <iostream> 
#include <iomanip> 
#include <conio.h> 
using namespace std;

 int main()
{   
int K;
   enum
   {
      jaanuar, veebruar, marts, aprill, mai, juuni, juuli, august, september, oktoober, november, detsember
   } Kuud;
cout<<"Sisestage kuu: ";               /* Asks for month*/
cin>> K;   
   

   if(K == jaanuar || K == veebruar || K == detsember)
      cout << K << "aastaaeg on talv" << endl;
   else if(K == oktoober || K == september || K == november)
      cout << K <<"aastaaeg on sugis" << endl; 
         else if(K == august || K == juuli || K == juuni)
      cout << K <<"aastaaeg on suvi" << endl;   
        else if(K == marts || K == aprill || K == mai)
      cout << K <<"aastaaeg on kevad" << endl;  
 
getch();
return 0;   
}

I do not know if I should laugh or cry right now.This got me right to the beginning, where the K in the result clause has random numerical value of 190..... something,which I experienced in my 2nd or 3rd try yesterday.

Last post has wrong piece of code in it.

Last post has wrong piece of code in it.

Last post has wrong piece of code in it.
Was This Post Helpful? 0
  • +
  • -

#30 jimblumberg  Icon User is offline

  • member icon


Reputation: 4142
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 12:58 PM

What are you inputting for the value of K and with that value what output do you expect your program to produce?

Also remember that your "months" are starting at zero, not 1.

Jim
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3