×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

I have a problem with a program i need to do i dont know where to star

I have a problem with a program i need to do i dont know where to star

I have a problem with a program i need to do i dont know where to star

(OP)
Hello
Thank howm ever that will give me of his time!!
I am a new student of C++
I need to do a program that will take a string and will
do the flowing
the string will be only from the : T ,F ,= ,* ,&&, ||;
and T=1 F=0 (true ,false)
The string will look like this Example:
T*F+F+T*F=T*T*T+F=T*F=
And in the output you need to brake the string in the
'=' sign and calculate the result so it will look like
T*F+F+T*F=F
T*T*T+F=T
T*F=T
The End !
Am i right ?! that is complex
please advise how to start and what to do?

RE: I have a problem with a program i need to do i dont know where to star

Not sure about the question but I hope this will get you
started. Let me know if I'm on the right track and we can
take it a bit further.


#include <stdio.h>

void main()
{
char string[] = "T*F+F+T*F=T*T*T+F=T*F=",*ptr;
ptr = string;
while(*ptr != '\0')
   {
   if(*ptr == '=')
      {
      /* do the sum here then increment the pointer */
      ptr++;
      }
   /* collect the sum here a char at a time */
   ptr++;
   }
}

RE: I have a problem with a program i need to do i dont know where to star

First thank you very much for trying to help
But this isnt what i had in mind i need to this
program only with strings and functions and without
pointers and the input should be for the
user to Enter
I alredy tryed a lot of directions but i only got lost
I cant fined the solution so i whould be very hapy if
you can help Again
Best Regards !

RE: I have a problem with a program i need to do i dont know where to star

Still don't understand but here is a variation on the last snippet using keyboard entry and a function. Why do you not want to use pointers, its much easier. This will allow you to input a string, pass it to the function and copy it to another string terminating at a '='.

#include <stdio.h>
void total(char result[20]);

void main()
{
char string[20];
gets(string);
total(string);
}

void total(char result[20])
{
char total[20];
int loop = 0;
while(result[loop]!= '=')
   {
   total[loop] = result[loop];
   loop++;
   }
}

RE: I have a problem with a program i need to do i dont know where to star

I am sorry but this steel dosent ansure my questition
i need to do it only with functions and strings
becouse that is what our teacher asked us our teacher
do not know how to teach and i very much strugling with
this problem i am sorry if i am driving you mad with my
problems !
i need to do it like this
with 4 functions
1 for callculation
2 to check " " and '+' '*'
and 2 more fore logical compute
if you could only direct me dont solve my problem
on how to start doing this i would thank you
and again i am sorry for all the hard work
i have done to you!!!! :)

RE: I have a problem with a program i need to do i dont know where to star

# include <stdio.h>

void main()
{
char *str,*res,ch;
int i=0,result=0;
printf("Enter the string :");


/*
To let the user only enter either a T,F,*,+,= or enter key.
*/


do
{
*(str+i)=getche();
if(*(str+i)!='T' || *(str+i)!='F' || *(str+i)!='+' || *(str+i)!='*' ||
*(str+i)!='=' || *(str+i)!=13)
     {
     printf("\a");
     i--;
     }
else i++;
}while(*(str+i-1)!=13);
length = i-1;

}


Now once you have these things in place. U know how to read one character at a time from string perform, the comparison and hence the operations. Hope this is not a Home assignment or that sort of thing, so I am not giving you the full code. Now I hope you can apply the logic of if result > 0 then print 'T' after equal to and if result = 0 then print 'F' after equal to. and then proceed on with the next series or string .. following equal to.


     I hope I could figure out your question correctly and as you had requested I have given you the logic for starting up. Try to work out this, if still facing problem, work again, its a good problem and will help you honing your logic.

Happy learning.
SwapSawe.
       
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close