Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

Aditi_Singh

  • 3 years ago

I'm such a newbie to c++ programming, and I really would appreciate the help!! Where did I go wrong with this program ? #include<iostream.h> 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 : "<<i;} else {r=12; i=p*r*t/100; cout<<"the interst is : "<<i;} }

  • This Question is Closed
  1. Aditi_Singh
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  2. Shadowys
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

  3. Shadowys
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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; }

  4. Shadowys
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

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

  5. Shadowys
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    the brackets are outside your declaration in the if statement

  6. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy