6 Replies - 591 Views - Last Post: 01 December 2010 - 01:43 PM Rate Topic: -----

#1 Guest_jojo*


Reputation:

where is my mistake

Posted 01 December 2010 - 11:01 AM

this is the program so far and i really cant see where is my mistake??????
when i run it its all wrong but why?? i`m new in this so can you help?

#include<iostream.h>
main()
{
      int i,y,rc=0,ec=0,ac=0,n=0;
      char choice;
      char x;
      cout<<"please enter your choice\n";
      cout<<"press a or A to count characters\npress b or B to sinx and series\npress c or C to count perfects,digits and prime number\npress d or D to Binary and Decimal\npress d or D to exit\n";
      cin>>choice;
       if(choice=='a'||choice=='A')
       cout<<"press 1 to count characters\npress 2 to change text number to integer\npress 3 to change from capital to small\npress 4 to return to the main menu\n";
       cin>>choice;
       if(choice=='1')
       {
       cout<<"enter your text\n";
       for(;x!='q';)/>
       {
       cin>>x;
       if(x=='a')
       ac=ac+1;
       else
       if(x=='r')
       rc=rc+1;
       else
       if(x=='e')
       ec=ec+1;
       cout<<"a="<<ac<<"r="<<rc<<"e="<<ec;
       break;
       }
       }
       if(choice=='2')
       {
       cout<<"enter your text number\n";
          for(;y!='q';)/>
          cin>>y;
          if(y>=48&&y<=57)
           n=n*10+(y-48);
       cout<<"the int is\n"<<n;
}


}


This post has been edited by macosxnerd101: 01 December 2010 - 11:02 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0

Replies To: where is my mistake

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

Re: where is my mistake

Posted 01 December 2010 - 11:08 AM

start by telling us what you are trying to do then tell us what as happening as opposed to what you think should happen. then we may be able to help ;)
Was This Post Helpful? 0
  • +
  • -

#3 Guest_jojo*


Reputation:

Re: where is my mistake

Posted 01 December 2010 - 11:14 AM

hello ishkabible

thank u for your support

ok

i`m trying to make a program to 1- count (e r a) characters ex: if i entered this text asrteadueda

it will count how many a e and r in it

next to change text number to integer
Was This Post Helpful? 0

#4 shadon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-November 10

Re: where is my mistake

Posted 01 December 2010 - 11:40 AM

plz could any one help !!
Was This Post Helpful? 0
  • +
  • -

#5 TomJoad  Icon User is offline

  • D.I.C Head

Reputation: 12
  • View blog
  • Posts: 54
  • Joined: 01-December 10

Re: where is my mistake

Posted 01 December 2010 - 01:00 PM

I've been using learncpp.com to, well, learn c++. Anyways, section 6.8 (http://www.learncpp.com/cpp-tutorial/68-pointers-arrays-and-pointer-arithmetic/)has almost exactly what you are looking for in the last snippet of code.

Now if I could only figure out a way so it will count words instead of letters...
Was This Post Helpful? 0
  • +
  • -

#6 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1335
  • View blog
  • Posts: 4,577
  • Joined: 19-February 09

Re: where is my mistake

Posted 01 December 2010 - 01:32 PM

Choice 1 works reasonably well,if you remove break.
Added int before main(), and braces for choice A if() statement.

Choice 2 is not working, y is already integer variable, the for statement continuously reads cin to y, and you can't put q in to exit.
Didn't look any further.

Look at using functions to break up your code.



#include<iostream.h>

//int added
int main()
{

  int i, y, rc=0, ec=0, ac=0, n=0;

  char choice;
  char x;

  cout << "please enter your choice\n";
  cout << "press a or A to count characters\n" 
       << "press b or B to sinx and series\n"
       << "press c or C to count perfects,digits and prime number\n" 
       << "press d or D to Binary and Decimal\n" 
       << "press d or D to exit\n";

  cin>>choice;

  if(choice=='a'||choice=='A')
  { // braces added
    cout << "press 1 to count characters\n" 
         << "press 2 to change text number to integer\n" 
         << "press 3 to change from capital to small\n" 
         << "press 4 to return to the main menu\n";

    cin>>choice;

    if(choice=='1')
    {
      cout<<"enter your text\n";
       
      for(;x!='q';)/>
      {
        cin>>x;
        if(x=='a')
          ac=ac+1;

        else if(x=='r')
          rc=rc+1;

        else if(x=='e')
         ec=ec+1;

        cout <<  "a=" << ac
             << " r=" << rc
             << " e=" << ec << endl;
        // break;
      }
    }
   

    if(choice=='2')
    {
      cout<<"enter your text number\n";

      // for(;y!='q';)/>
      // y is not character
      cin >> y;

      if(y>=48 && y<=57)
        n=n*10+(y-48);

      cout<<"The int is " << n << "\n";
    }


  }

  cout << "Press any key to exit";
  cin.ignore();
  cin.get();
  return(0);
}

Was This Post Helpful? 0
  • +
  • -

#7 shadon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 22-November 10

Re: where is my mistake

Posted 01 December 2010 - 01:43 PM

TomJoad

thank you for your help i really appreciated it

define

thank you i will try it , i cant find the words to thank you so :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1