Having few errors in the code

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

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

#31 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 - 01:06 PM

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

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

input of the value of K is jaanuar. The output is expected to be:"Kuu jaanuar aastaaeg on kevad" ( Month January's season is spring)
I did remember that and used your tip to fix the input in this other, more inefficient piece of code, which has the same problem.
#include <iostream> 
#include <iomanip> 
#include <conio.h> 
using namespace std;

 int main()
{   
int K;
   enum
   {
      jaanuar=1, veebruar, marts, aprill, mai, juuni, juuli, august, september, oktoober, november, detsember
   } kuud;
cout<<"Sisestage kuu: ";               /* Asks for month*/
cin>> K;   
   
  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; 
} 




The problem is that if my input is number 12, the output is correct.
Was This Post Helpful? 0
  • +
  • -

#32 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 - 01:23 PM

Input number is 1* ,when I mean January.
Was This Post Helpful? 0
  • +
  • -

#33 jimblumberg  Icon User is offline

  • member icon


Reputation: 3991
  • View blog
  • Posts: 12,315
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 01:23 PM

Quote

input of the value of K is jaanuar.

Your variable K is an int so you need to enter a number, not something like "jaanuar". If your want to enter something like "jaanuar" then you need to use a string instead of an int, and an array of string instead of the enum.

So exactly what are you trying to accomplish?


Jim
Was This Post Helpful? 0
  • +
  • -

#34 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 - 01:24 PM

So that way the output is correct: Kuu Jaanuar aastaaeg on talv.
Was This Post Helpful? 0
  • +
  • -

#35 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 - 01:30 PM

View Postjimblumberg, on 13 January 2013 - 01:23 PM, said:

Quote

input of the value of K is jaanuar.

Your variable K is an int so you need to enter a number, not something like "jaanuar". If your want to enter something like "jaanuar" then you need to use a string instead of an int, and an array of string instead of the enum.

So exactly what are you trying to accomplish?


Jim

So using the string and array is the only way to accomplish the output required?
Was This Post Helpful? 0
  • +
  • -

#36 jimblumberg  Icon User is offline

  • member icon


Reputation: 3991
  • View blog
  • Posts: 12,315
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 01:36 PM

What are you trying to accomplish?

Please explain exactly what you are trying to do. Show a sample input and exactly what you expect your program to output with that input.

Jim
Was This Post Helpful? 0
  • +
  • -

#37 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 - 01:46 PM

View Postjimblumberg, on 13 January 2013 - 01:36 PM, said:

What are you trying to accomplish?

Please explain exactly what you are trying to do. Show a sample input and exactly what you expect your program to output with that input.

Jim

Trying to conduct a program that when entering an input of any of the 12 months it gives me the output of:"Month X's season is Y".
Where X is the month that user enters to the program and the Y is the season,which is connected to the user's input of the month.
Once more, I am not a native speaker, so if you have trouble understanding me well,there is'nt much I can do about it.
Was This Post Helpful? 0
  • +
  • -

#38 jimblumberg  Icon User is offline

  • member icon


Reputation: 3991
  • View blog
  • Posts: 12,315
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 02:05 PM

Are you trying to enter the month as a string, like "jaanuar"?

Please show exactly what you are trying to enter.

Jim
Was This Post Helpful? 0
  • +
  • -

#39 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 - 02:29 PM

View Postjimblumberg, on 13 January 2013 - 02:05 PM, said:

Are you trying to enter the month as a string, like "jaanuar"?

Please show exactly what you are trying to enter.

Jim

Yes, I am trying to enter: jaanuar
Was This Post Helpful? 0
  • +
  • -

#40 jimblumberg  Icon User is offline

  • member icon


Reputation: 3991
  • View blog
  • Posts: 12,315
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 02:54 PM

Then the variable you are using for your user input must be a string, not an int. Have you studied std::string yet?

Jim
Was This Post Helpful? 0
  • +
  • -

#41 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 - 03:33 PM

View Postjimblumberg, on 13 January 2013 - 02:54 PM, said:

Then the variable you are using for your user input must be a string, not an int. Have you studied std::string yet?

Jim

It seems that this is not the case. However, for my last excercise, this was linked as a hint:http://www.cplusplus.com/reference/string/string/substr/
Was This Post Helpful? 0
  • +
  • -

#42 jimblumberg  Icon User is offline

  • member icon


Reputation: 3991
  • View blog
  • Posts: 12,315
  • Joined: 25-December 09

Re: Having few errors in the code

Posted 13 January 2013 - 04:04 PM

Well the link you posted is using std::string, so maybe you need to review your notes from your classes. This can be done by using a std::string and then comparing that string similar to what you are doing with the numbers.

Jim
Was This Post Helpful? 0
  • +
  • -

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