help getting program to add second function to first

Ask for help with your homework/assignments in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

help getting program to add second function to first

Postby tzfrantic » Thu Apr 26, 2012 8:54 am

here is my code that works but for this program when it manipulations the second function meaning when it turns for example 23 to 32 i need help getting
it to add to the first function when it is manitipated here is the code.

Code: Select all
#include<iostream.h>
#include<string>
#include<stdio.h>


//Function Prototype declaration
void searchChar(string);

void reversal(string&);

void caps(string&);

void printstr(string,string);

int main()
{
    string str1,str2;
    int choice;
    cout<<"Please Enter String 1 : ";
    cin>>str1;
    cout<<"Please Enter String 2 : ";
    cin>>str2;
    cout<<"String 1 : "<<str1<<endl;
    cout<<"String 2 : "<<str2<<endl;
    do
    {
     cout<<"Options available for String 2 Manipulation : "<<endl;
     cout<<"1. Search a character in String ?"<<endl;
     cout<<"2. Reverse the String ?"<<endl;
     cout<<"3. Change the case of String ?"<<endl;
     cout<<"4. Reverse and Change Case of String ?"<<endl;
     cout<<"5. EXIT ?"<<endl;
     cout<<"Please Enter your choice : ";
     cin>>choice;
     switch(choice)
     {
        case 1 :
            searchChar(str2);
            printstr(str1,str2);
            break;
        case 2 :
             reversal(str2);
             printstr(str1,str2);
             break;
        case 3:
             caps(str2);
             printstr(str1,str2);
             break;
        case 4 :
             reversal(str2);
             caps(str2);
             printstr(str1,str2);
             break;
        case 5 :
             break;
        default :
                cout<<"Wrong Menu Choice!!"<<endl;
     }
    }while(choice != 5);
   
    getchar();
   
    return 0;
}


void searchChar(string st)
{
     char ch;
     int check = 0;
     cout<<"Enter a character to search :";
     cin>>ch;
     for(int i=0;i<st.size();i++)
     {
              if(ch==st[i])
              {
                 cout<<"Character \'"<<ch<<"\' is present in String \""<<st<<"\" at position : "<<(i+1)<<endl;
                 check++;
              }
     }
     if(check == 0)
     {
        cout<<"Character not present in String 2. "<<endl;
     }
}

void reversal(string& st)
{
       char temp;
       for(int i=0;i<st.size()/2;i++)
       {
               temp = st[i];
               st[i] = st[(st.size() - i-1)];
               st[(st.size() - i-1)] = temp;
       }       
}

void caps(string& st)
{
     for(int i=0;i<st.size();i++)
     {
             if(st[i]>=97 && st[i]<=122)
                 st[i] = st[i] - 32;
     }     
}

void printstr(string st1,string st2)
{
    cout<<endl<<"String : "<<st1<<" "<<st2<<endl<<endl;
}
tzfrantic
 
Posts: 4
Joined: Mon Apr 16, 2012 2:19 pm

Re: help getting program to add second function to first

Postby exomo » Thu Apr 26, 2012 3:14 pm

Sorry, I don't get it. What do you want the program to do? How do you want to add functions?

btw: If this code compiles without errors you must be using a very old compiler. You should consider updating it. (See the sticky thread in the for beginners section)
And you should use getline for input, cin>> is so ugly. (see http://cpp-home.com/forum/viewtopic.php?f=4&t=17544 for some of my comments in another thread)
Who needs a signature anyway.
User avatar
exomo
 
Posts: 879
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Re: help getting program to add second function to first

Postby tzfrantic » Sun Apr 29, 2012 6:58 am

ok his is what i mean string 1 is 12 and second string is 23 when i run the program and select to manipulate it
the second string goes to 32 which is half of what i want.but what i want it to do is for the second and first string to add to each other that is 12 + 23 which is 35 so then both at the same time when i select the option to manuplate that it adds the first and second string together which equals 35 but it is 53 when manipated i already have the code to maniplate all i need is the code to add the 2 strings together (first string 12+23 second string).
tzfrantic
 
Posts: 4
Joined: Mon Apr 16, 2012 2:19 pm

Re: help getting program to add second function to first

Postby exomo » Sun Apr 29, 2012 2:58 pm

To add strings you have to convert them to numbers first.
I posted a simple number conversion function in the thread I linked in my first reply.
Who needs a signature anyway.
User avatar
exomo
 
Posts: 879
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Re: help getting program to add second function to first

Postby tzfrantic » Mon Apr 30, 2012 10:35 am

i have the strings converted all i need is for them to add for example the first string is 23 the second string is 25 so that equals to 48 but i do not know what code to put it to add them together
tzfrantic
 
Posts: 4
Joined: Mon Apr 16, 2012 2:19 pm

Re: help getting program to add second function to first

Postby exomo » Mon Apr 30, 2012 3:44 pm

So whats the problem then?
Code: Select all
int a = 23;
int b = 48;
int c = a + b;
Who needs a signature anyway.
User avatar
exomo
 
Posts: 879
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden


Return to Homeworks

Who is online

Users browsing this forum: No registered users and 3 guests