help on code

C, C++, Visual C++, C++.Net Topics
User avatar
Face
Major
Major
Posts: 727
Joined: Thu Feb 18, 2010 5:06 pm
Location: SRI LANKA.KANDY.

Re: help on code

Post by Face » Wed Nov 24, 2010 8:01 pm

NEO sorry about the late reply.I am busy with much professional work,as a trainee in probation period in his first job exp.
I am doing IT as a hobby.
I thought to changing my code variable type on those variables M,C,T,Q.
It gave me good reaction.When I use int it shows 0 as answer when it has to show answer<0.Now is is ok.

Code: Select all

//calculate Q=MCT

#include<iostream>
using namespace std;

int main(){
    float m,c,t,q,z;
    char x;
    cout<<"We are goig to calculate Q=MCT"<<endl<<endl;
    cout<<"Enter what you wanna calculate Q or M or C or T -"<<endl<<endl;
    cin>>x;
    
    if(x=='q'){
               cout<<"enter your dimentions - "<<endl;
               cout<<"M - ";
               cin>>m;
               cout<<endl<<"C - ";
               cin>>c;
               cout<<endl<<"T - ";
               cin>>t;
               q=m*c*t;
               cout<<endl<<"Your anser for Q - "<<q;
               cout<<endl<<"thank you for using this program ";
               system("pause");
               return 0;
    }
    else if(x=='m'){
         cout<<"enter your dimentions - "<<endl;
         cout<<"Q - ";
         cin>>q;
         cout<<endl<<"C - ";
         cin>>c;
         cout<<endl<<"T - ";
         cin>>t;
         z=(c*t);
         m=q/z;
         cout<<endl<<"Your anser for M - "<<m;
         cout<<endl<<"thank you for using this program ";
         system("pause");
         return 0;
    }
    else if(x=='c'){
          cout<<"enter your dimentions - "<<endl;
          cout<<"Q - ";
          cin>>q;
          cout<<endl<<"M - ";
          cin>>m;
          cout<<endl<<"T - ";
          cin>>t;
          z=(m*t);
          c=q/z;
          cout<<endl<<"Your anser for c - "<<c;
          cout<<endl<<"thank you for using this program ";
          system("pause");
          return 0;
    }
    else if(x=='t'){
                 cout<<"enter your dimentions - "<<endl;
                 cout<<"Q - ";
                 cin>>q;
                 cout<<endl<<"M - ";
                 cin>>m;
                 cout<<endl<<"C - ";
                 cin>>t;
                 z=(m*c);
                 t=q/z;
                 cout<<endl<<"Your anser for T - "<<t;
                 cout<<endl<<"thank you for using this program ";
                 system("pause");
                 return 0;
    }
    
    system("pause");
    return 0;
    
    }
I will try to make some codes after reading that tutorial carefully.
Post Reply

Return to “C/C++ Programming”