How to display alphabet base on a number given

Hi i am a beginner in c++

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  #include <iostream>
#include <string>
#include <cmath>

using namespace 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;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 #include <iostream>
#include <string>
#include <cmath>

using namespace 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;

}
Last edited on
thanks really appreciate your help :)

i didnt know i need to put " " for the string part, thanks alot

initially i put zero because i thought we needed to set some value to it as i see in some of the problem
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 =)
Topic archived. No new replies allowed.