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?
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
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
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
#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 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
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.