Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

I'm such a newbie to c++ programming, and I really would appreciate the help!! Where did I go wrong with this program ? #include void main() {float p,r,t,i; cout<<"Enter the principal amount: "; cin>>p; cout<<"Enter the time period: "; cin>>t; if(t>10) r=8; i=p*r*t/100; {cout<<"the interest is : "<

OpenStudy (anonymous):

p.s : It says : misplaced else in function main() And, Yeah, The question was : WAP to input principal amount and time. If time is more than 10 years, calculate the simple interest at the rate of 8%, otherwise calculate is at the rate of 12% per annum

OpenStudy (anonymous):

if(t>10) r=8; i=p*r*t/100; {cout<<"the interest is : "<<i;} else {r=12; i=p*r*t/100; cout<<"the interst is : "<<i;} notice the brackets.

OpenStudy (anonymous):

here's the code after some debugging. #include<iostream> using namespace std; int main() {float p,r,t,i; cout<<"Enter the principal amount: "; cin>>p; cout<<"Enter the time period: "; cin>>t; if(t>10) {r=8; i=p*r*t/100; cout<<"the interest is : "<<i;} else {r=12; i=p*r*t/100; cout<<"the interst is : "<<i;} return 0; }

OpenStudy (anonymous):

the main function must return an integer. void is for functions inside it.

OpenStudy (anonymous):

the brackets are outside your declaration in the if statement

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!