ABC Problem

My teacher give me a homework.I'm a kid from thailand
She said if you don't understand you can ask someone else

Given 3 Interger A,B and C it may not ordering but we know as A<B<C

Question
Ordering the Given Number

Input Data
First line Including 3 number, left 1 space each that 3 number must less than 100
Second line Including 3 letter is A,B and C by noft left space this is the ordering if the number

output data
only one line and order as the given input order

Example
input------output
1 5 3 ----->1 3 5
ABC
6 4 2 ------>6 2 4
CAB
Last edited on
i'm post code like this
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include<stdio.h>
int main()
{
    int a,b,c,;
    char n;
    scanf("%d\t",&a);
    scanf("%d\t",&b);
    scanf("%d\n",&c);
    scanf("%s",&n);
    if(a<b<c){
    if(n=ABC){
    printf("%d %d %d",a,b,c);
    }
    if(n=BAC){
    printf("%d %d %d",b,a,c);
    }
    if(n=CAB){
    printf("%d %d %d",c,a,b);
    }
    if(n=ACB){
    printf("%d %d %d",a,c,b);
    }
    if(n=BCA){
    printf("%d %d %d",b,c,a);
    }
    if(n=CBA){
    printf("%d %d %d",c,b,a);
    }
    else{
         printf("Invalid Input");
    }
    /*Second Part BAC*/
    if(b<a<c){
    if(n = ABC){
    printf("%d %d %d",b,a,c);
    }
    if(n=BAC){
    printf("%d %d %d",a,b,c);
    }
    if(n=CAB){
    printf("%d %d %d",c,b,a);
    }
    if(n=ACB){
    printf("%d %d %d",b,c,a);
    }
    if(n=BCA){
    printf("%d %d %d",a,c,b);
    }
    if(n=CBA){
    printf("%d %d %d",c,a,b);
    }
    else{
         printf("Invalid Input");
    }
    /*Third Part CAB*/
    if(c<a<b){
    if(n=ABC){
    printf("%d %d %d",c,a,b);
    }
    if(n=BAC){
    printf("%d %d %d",a,c,b);
    }
    if(n=CAB){
    printf("%d %d %d",b,c,a);
    }
    if(n=ACB){
    printf("%d %d %d",c,b,a);
    }
    if(n=BCA){
    printf("%d %d %d",a,b,c);
    }
    if(n=CBA){
    printf("%d %d %d",b,a,c);
    }
    else{
         printf("Invalid Input");
    }
     /*Fourth Part ACB*/     
    if(a<c<b){
    if(n=ABC){
    printf("%d %d %d",a,c,b);
    }
    if(n=BAC){
    printf("%d %d %d",c,a,b);
    }
    if(n=CAB){
    printf("%d %d %d",b,a,c);
    }
    if(n=ACB){
    printf("%d %d %d",a,b,c);
    }
    if(n=BCA){
    printf("%d %d %d",c,b,a);
    }
    if(n=CBA){
    printf("%d %d %d",b,c,a);
    }
    else{
         printf("Invalid Input");
    }
    /*Fifth Part BCA*/  
    if(b<c<a){
    if(n=ABC){
    printf("%d %d %d",b,c,a);
    }
    if(n=BAC){
    printf("%d %d %d",c,b,a);
    }
    if(n=CAB){
    printf("%d %d %d",a,b,c);
    }
    if(n=ACB){
    printf("%d %d %d",b,a,c);
    }
    if(n=BCA){
    printf("%d %d %d",c,a,b);
    }
    if(n=CBA){
    printf("%d %d %d",a,c,b);
    }
    else{
         printf("Invalid Input");
    }
    /*Sixth Part CBA*/  
    if(c<b<a){
    if(n=ABC){
    printf("%d %d %d",c,b,a);
    }
    if(n=BAC){
    printf("%d %d %d",b,c,a);
    }
    if(n=CAB){
    printf("%d %d %d",a,c,b);
    }
    if(n=ACB){
    printf("%d %d %d",c,a,b);
    }
    if(n=BCA){
    printf("%d %d %d",b,a,c);
    }
    if(n=CBA){
    printf("%d %d %d",a,b,c);
    }
    else{
         printf("Invalid Input");
    }
    else{
         printf("Invalid Input");
    }

i don't know why n=ABC is undeclare
(This is C, right?)

On line 11 you write if (n = ABC), ABC is undeclared (you didn't tell the compiler what ABC is, same for the other permutations).

Also, I think you mean something like if (n == ABC)?

The design has to be reviewed. It's better (and looks better) if you use an array and sort the numbers.
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
#include <algorithm>
#include <iostream>
using namespace std;


int main(int argc, char **argv)
{
	// store the numbers in array
	int numbers[3];
	// store the order of chars
	char char_order[3];

	
	// 1th section: read data
	cout << "please write three numbers: ";
	for ( int i = 0; i < 3; i++ ) cin >> numbers[i];
	cout << endl;
	
	cout << "please write upper case letters like 'ABC': ";	
	for ( int i = 0; i < 3; i++ ) cin >> char_order[i];
	// convert characters to numbers. A=0 B=1 C=2
	for ( int i = 0; i < 3; i++ ) char_order[i] = char_order[i] - 'A';

	// 2th Section: sort the numbers
	sort( numbers, numbers + 3 );
	
	
	// 3th Section: write the numbers in desired order
	for ( int i = 0; i < 3 ; i++ )cout << numbers[char_order[i]];
	cout << endl << "Numbers in ddesired order" << endl;
	cin.get();
	return 0;
}
Last edited on
Topic archived. No new replies allowed.