Thread: confused

  1. #1
    Registered User
    Join Date
    Nov 2010
    Location
    London, UK
    Posts
    18

    confused

    I am trying to make a program that will take 2 letters (representing numbers all the way to 26 respectively) and an integer of 1 to 1,000,000. They are all added together and the result is a number representative of a letter. I need to output a single capital letter, the nth letter in the sequence that starts with the input letters. My code does not work at all and I am really really lost.
    this is my code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    	
    int main (int argc, const char * argv[]) 
    {
    	
    	int userLetter1 = 0;
    	int userLetter2 = 0;
    	int userNumber1 = 0;
    	
    	//int internal1 = 0;
    	//Assigning values to letters
       
    	int A=1;
    	int B=2;
    	int C=3;
    	int D=4;
    	int E=5;
    	int F=6;
    	int G=7;
    	int H=8;
    	int I=9;
    	int J=10;
    	int K=11;
    	int L=12;
    	int M=13;
    	int N=14;
    	int O=15;
    	int P=16;
    	int Q=17;
    	int R=18;
    	int S=19;
    	int T=20;
    	int U=21;
    	int V=22;
    	int W=23;
    	int X=24;
    	int Y=25;
    	int Z=26;
    	
    	//const int overloadNumber = 26;
    	//int outputAnswer = 0;
    	
    //Asking for user input
    	
    	printf("Enter first letter : \n");
    	scanf("%d", &userLetter1);
    	switch (userLetter1) {
    		case A:
    			A=1;
    			break;
    		case B:
    			B=2;
    			break;
    		case C:
    			C=3;
    			break;
    		case D:
    			D=4;
    			break;
    		case E:
    			E=5;
    			break;
    		case F:
    			F=6;
    			break;
    		case G:
    			G=7;
    			break;
    		case H:
    			H=8;
    			break;
    		case I:
    			I=9;
    			break;
    		case J:
    			J=10;
    			break;
    		case K:
    			K=11;
    			break;
    		case L:
    			L=12;
    			break;
    		case M:
    			M=13;
    			break;
    		case N:
    			N=14;
    			break;
    		case O:
    			O=15;
    			break;
    		case P:
    			P=16;
    			break;
    		case Q:
    			Q=17;
    			break;
    		case R:
    			R=18;
    			break;
    		case S:
    			S=19;
    			break;
    		case T:
    			T=20;
    			break;
    		case U:
    			U=21;
    			break;
    		case V:
    			V=22;
    			break;
    		case W:
    			W=23;
    			break;
    		case X:
    			X=24;
    			break;
    		case Y:
    			Y=25;
    			break;
    		case Z:
    			Z=26;
    	}
    	printf("Enter second letter : \n");
    	scanf("%d", &userLetter2);
    	switch (userLetter1) {
    		case A:
    			A=1;
    			break;
    		case B:
    			B=2;
    			break;
    		case C:
    			C=3;
    			break;
    		case D:
    			D=4;
    			break;
    		case E:
    			E=5;
    			break;
    		case F:
    			F=6;
    			break;
    		case G:
    			G=7;
    			break;
    		case H:
    			H=8;
    			break;
    		case I:
    			I=9;
    			break;
    		case J:
    			J=10;
    			break;
    		case K:
    			K=11;
    			break;
    		case L:
    			L=12;
    			break;
    		case M:
    			M=13;
    			break;
    		case N:
    			N=14;
    			break;
    		case O:
    			O=15;
    			break;
    		case P:
    			P=16;
    			break;
    		case Q:
    			Q=17;
    			break;
    		case R:
    			R=18;
    			break;
    		case S:
    			S=19;
    			break;
    		case T:
    			T=20;
    			break;
    		case U:
    			U=21;
    			break;
    		case V:
    			V=22;
    			break;
    		case W:
    			W=23;
    			break;
    		case X:
    			X=24;
    			break;
    		case Y:
    			Y=25;
    			break;
    		case Z:
    			Z=26;
    	}
    	
    	printf("Enter integer : \n");
    	scanf("%d", &userNumber1);
    	
    	
    	return 0;
    	
    	
    }

  2. #2
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    You do know you don't need to do all of that work...

    run this and look at the output...

    Code:
    #include <stdio.h>
    
    int main(){
            printf("Letter A = %d", 'A');
            return 0;
    }
    You can cast simply without the need to actually write out what every character is.

    Or even, you can use atoi() function.
    Last edited by \007; 12-07-2010 at 05:16 AM.

  3. #3
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    Does this float your boat,

    Code:
    #include <stdio.h>
    
    int main(){
      char a, b;
      int num;
    
      printf("\nEnter two characters and a number seperated by a space: ");
      scanf("%c %c %d",&a,&b,&num);
    
      printf("Add them up and we get....%d\n", (a+b+num));
    
      return 0;
    }
    Or, do you want something more complicated? Because that's how I read it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Confused about Memory
    By gL_nEwB in forum C++ Programming
    Replies: 22
    Last Post: 06-20-2006, 07:32 PM
  2. Confused
    By jeev2005 in forum C Programming
    Replies: 5
    Last Post: 06-01-2006, 02:04 PM
  3. Confused
    By (TNT) in forum C# Programming
    Replies: 1
    Last Post: 11-23-2005, 04:49 PM
  4. why wont this compile?!? :confused:
    By jdude in forum C++ Programming
    Replies: 5
    Last Post: 11-25-2004, 01:13 AM
  5. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM