Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
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?
 
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[] = &quot;T*F+F+T*F=T*T*T+F=T*F=&quot;,*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++;
}
}
 
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 !
 
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++;
}
}

 
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 &quot; &quot; 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!!!! :)
 
# include <stdio.h>

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


/*
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(&quot;\a&quot;);
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.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top