it is always giving the same output which is "you entered wrong letter"

+2 hilmi kumdakçı · January 22, 2015
last version of my code :


#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main()
{

string a,A,V;
    double b,x,y,z;


cout<<"Which one is leading phase?\nV or A?"<<endl;
cin>>a;
cout<<"What is the phase difference which is expressed in degrees ?"<<endl;
cin>>b;
cout<<"What is the peak value of V?"<<endl;       
cin >>y;
cout<<"What is the peak value of A"<<endl;
cin>>z;

if(a=="V")
{


   for(double x=1; x<200;x++){
cout<<x/512<<"sec"<< y*sin(0.6135*x) <<"V"<< z*sin(0.6135*x+0.01745*b) <<"A"<<endl;
  }
    }
if (a=="A")
{
for(double x=1;x<200;x++){

cout<<x/512<<"sec"<<          sin(0.6135*x) <<"A"<<           sin(0.6135*x+0.01745*b) <<"V"<<endl;
}

}
else{

cout<<"You entered wrong letter";
         }
return 0;

    
    }

Post a Reply

Replies

Oldest  Newest  Rating
+2 Jake Scaife · January 23, 2015
I'm not 100% sure what you are trying to achieve here, but my tips would be to firstly use the code tags so that it makes it easier to read your code and secondly use some indentation.

From what I can see, you are testing the variable 'a' against variables 'V' and 'A' which you have declared... but don't have a value. Therefore the if statements will never return true, unless the variable 'a' also doesn't have a value - which I doubt is what you are trying to achieve here. This is the reason you are getting the same output from the program.

If you need any help just let us know, or refer to Bucky's c++ tutorials, they are a great place to cement your knowledge in c++.
+1 Bernard Pyc0d333 Parah · January 23, 2015

#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main()
{

string a,A,V; // YOU DECLARED THEM AS STRINGS.
double b,x;


cout<<"Which one is leading phase?\nV or A?"<<endl;
cin>>a;
cout<<"what is the phase difference which is expressed in degrees ?"<<endl;
cin>>b;

if(a=="V")   //V HAS BEEN DECLARED AS A STRING, SO YOUR COMPARISON SHOULD BE WITH A STRING
{

    for(double x=1; x<200;x++)
   {
cout<<x/512<<"sec"<< sin(0.6135*x) <<"V"<< sin(0.6135*x+0.01745*b) <<"A"<<endl;
   }
}

if (a=="A") //SAME AS V
    {
        for(double x=1;x<200;x++){

        cout<<x/512<<"sec"<< sin(0.6135*x) <<"A"<< sin(0.6135*x+0.01745*b) <<"V"<<endl;
    }

}

else

cout<<"You entered wrong letter";

return 0;
}

I suggest that you declare A and V as char values since you are accepting only a single character, I dunno about using math.h cos I think cmath does the same thing.
+3 Val Almosnino · January 23, 2015
V and A are string values and need to be surrounded by double quotes in your if statements.


.
.
.
if(a=="V")
.
.
.
if(a=="A")
.
.
.
+1 Bernard Pyc0d333 Parah · January 23, 2015
yea Val. true.
0 hilmi kumdakçı · January 23, 2015
thanks for all ur answers . I have done it but have some questions. btw was trying to get a voltage and amper values in som seconds which are going with 50hz.  after some  calculations found tihs values and ? added two more variables to indicatehttps://cdncache-a.akamaihd.net/items/it/img/arrow-10x10.png amplitude of them . anyway;

1. the grogram gives me 0.57 as a value of sin(0.635) (for x=1) it does not make sense . the rest values are also incorrect . i changed library and made it math.h but it is still incorrect .(i handled with this problem it gives me the value in terms of radian i converted it to degree)

2. is there any way to write the output to a file or something else which is seen nicer than black screen ?

3. after 200 loops it gave me the output "you entered wrong letter " . how can i avoid from it ?
+2 Çağlan Turgut · January 25, 2015
2. If you mean command prompt, well it has a black background on Windows but its equivalents on other operating systems(terminals) have different background colors(Mac OS X >> White; Ubuntu >> Purple). 


You can output to an application window;



  • Using your target Operating Systems API or 





You can output to a file;





!Keep in mind that some text readers might have black background!
0 hilmi kumdakçı · January 25, 2015
? have done it by using fstream . thanx
  • 1

C++

107,336 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator