i would like to ask how do i display a alphabet base on a number given, the below is my code, i tried to display a number base on the number given and it works, may i know why couldn't i display a alphabet . thanks alot
#include <iostream>
#include <string>
#include <cmath>
usingnamespace std;
int main()
{
double strength;
string material ;
string A = 0 ;
string B = 0;
string response ;
cout<<"Welcome to xxx Calculator"<<endl;
cout <<"Please enter strength of material needed : " ;
cin >>strength;
if ( strength < 100 )
material = A ;
else
material = B ;
cout <<"The material that we recommend you to use is"<<material<<"."<<endl<<"Thanks for choosing xxx calculator"<<endl ;
system ("pause");
return 0;
}
#include <iostream>
#include <string>
#include <cmath>
usingnamespace std;
int main()
{
double strength;
string material ;
string A = "ABC" ; // Not sure why you initialized them to 0.
string B = "DEFG" // Wouldnt you want A,B to be equal to the alphabet you want to display?
string response ;
cout<<"Welcome to xxx Calculator"<<endl;
cout <<"Please enter strength of material needed : " ;
cin >>strength;
if ( strength < 100 )
material = A ;
else
material = B ;
cout <<"The material that we recommend you to use is "<<material<<"."<<endl<<"Thanks for choosing xxx calculator"<<endl ;
system ("pause");
return 0;
}
Initializing is good and you should do it, but your problem was that you never gabe A and B a value, so when you did this - material = A ; Nothing really happened =)