Still need help!!

Ok so I have this program here that a user selects the number of computations they want to do. then they select which computation. Now i have it looped, I just don't know how to print the computations that the user selected IN THE ORDER the user selected.

Also I can only use switch, if, int/double, for, while, and do while loops.

No arrays or strings.

Help me out here I've tried a few different things and I can't get it. If anyone can help or come up with a function/method let me know please.

here is the code so far.


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
void main()
{	int comp;
	int choice;
	int one=0;
	int two=0;
	int three=0;
	int four=0;
	int five=0;
	printf("\nThis program is a program for selecting computations");
	printf("\n\nEnter number of computations [0-5]:");
	scanf("%i", &comp);
	while (comp<0 || comp>5)
	{
		printf("\t%i is not a valid entry",comp);
		printf("\n\nEnter number of computations [0-5]:");
		scanf("%i", &comp);
	}
	if (comp==0)
	{
		printf("\n\nEnd program\n");
	}
	for (int x = 0; x<comp; x++)
	{
		if (one==0)
		{
			printf("\n\t1 - Surface area of a cylinder");
		}
		if (two==0)
		{
			printf("\n\t2 - Surface area of a cone");
		}
		if (three==0)
		{
			printf("\n\t3 - Radius of a circle sector");
		}
		if (four==0)
		{
			printf("\n\t4 - Volume of a cylinder");
		}
		if (five==0)
		{
			printf("\n\t5 - Volume of a sphere");
		}
		printf("\n\nEnter a computation:");
		scanf("%i",&choice);
		if (choice==1 && one==0)
		{
			one++;
		}
		else if(choice==2 && two==0)
		{
			two++;
		}
		else if(choice==3 && three==0)
		{
			three++;
		}
		else if(choice==4 && four==0)
		{
			four++;
		}
		else if(choice==5 && five==0)
		{
			five++;
		}
		else
		{
			printf("%i is not a valid entry",choice);
			x--;
		}
	}
}	
Last edited on
You would have to store their selections in some sort of container, like a string or vector.
you need to remember the selection somehow, as you have said that you do not use arrays and strings so the only way i can think of right now is to create an integer and store the selection values in it.

int remember (0) //variable initialized to zero
if(choice>0 && choice<6)
{
remember=(remember*10)+choice; //so you get the selection saved in the variable i.e 43241
}
/*

now whenever you need the first selected choice of user first check for the number of digits in "remember" variable.
e.g for 43241 number of digits is 5 (save '5' in a temporary variable TEMP ) so use
remember/(pow(1,TEMP-1)) , this will give you first choice of user,....
*/

//however note that this method is not very effective as it will only save 9 selections

@chillfill: If you can't post a reasonable solution to the issue, don't confuse people by posting solutions that will cause confusion.
@ciphermagi

can't use strings. already said that once read the post please. and because of that I don't know what to do.

@chillfill

thanks for the help but i don't really understand what you're trying to do.
basically what is going on is that if they select the first number to be 1 then it'll list 5 computations. then the user will select one of those and then it will print the one it selected.

now it gets more complicated because if the user selects 5, then it will list the 5 computations and the user will pick 5 of them in a random order. what the program has to do now is print those in the order the user selected.

keep the ideas coming cause idk what to do.
A string is a container. I didn't say to use a string, I said to use a container. I could list probably 20 different container types without it being either a string or an array.

Use int main() because void main is going to cause problems.

You can declare a list of variables of the same type inline, like int comp, choice, one = 0, two = 0, three = 0, four = 0, five = 0;

You're repeating code. Use a do{...}while(); loop instead of a while.

This doesn't do anything, it has no purpose:
1
2
3
4
if (comp==0)
{
	printf("\n\nEnd program\n");
}


All of those if statements in the beginning of your for loop will be true only one time each.

Again, the if-else statements will only be true one time each.

Why don't you just do the computation immediately after each choice, and then continue looping until they've chosen five computations?
actually that if (comp==0) does do something. In the interval when it says pick a number [0-5], if they pick 0 it suppose to display end program.
also i don't have to do the computations. I just have to display what computations they picked.

so instead of the if statements, what would need to happen to make them true all the time. Would I have to make them a cases or find another way?

this project is suppose to help us understand the coding but to do this without arrays and strings is hard to understand. I don't know how to approach it any other way but if statements but that is apparently wrong.
I fixed my loop so it goes back around. I still can't figure out how to store the numbers the user enters and then display the them in the order they selected. here is what i have

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
#include <stdio.h>

void main()
{
	int comp, one=0, two=0, three=0, four=0, five=0, choice, y;
	printf("This is a program for selecting computations.");
	do
	{
		one=0, two=0, three=0, four=0, five=0, choice, y;
		printf("\n\nEnter the number of computations [0-5]:");
		scanf("%i",&comp);
		while (comp < 0 || comp > 5)
		{
			printf("\t%i is not a valid number.",comp);
			printf("\n\nEnter the number of computations [0-5]:");
			scanf("%i",&comp);
		}
		if (comp==0)
		{
			printf("\n\nEnd program\n");
		}
		for (int x = 0; x<comp; x++)
		{
		if (one==0)
		{
			printf("\n\t1 - Surface area of a cylinder");
		}
		if (two==0)
		{
			printf("\n\t2 - Surface area of a cone");
		}
		if (three==0)
		{
			printf("\n\t3 - Radius of a circle sector");
		}
		if (four==0)
		{
			printf("\n\t4 - Volume of a cylinder");
		}
		if (five==0)
		{
			printf("\n\t5 - Volume of a sphere");
		}
		printf("\n\nEnter a computation:");
		scanf("%i",&choice);
		if (choice==1 && one==0)
		{
			one++;
		}
		else if(choice==2 && two==0)
		{
			two++;
		}
		else if(choice==3 && three==0)
		{
			three++;
		}
		else if(choice==4 && four==0)
		{
			four++;
		}
		else if(choice==5 && five==0)
		{
			five++;
		}
		else
		{
			printf("%i is not a valid entry",choice);
			x--;
		}
	}
}
	while (comp!=0);
}
Topic archived. No new replies allowed.