Arrays with while loop help (homework)

Hello, im new to programming and I have an assignment where I can't get passed the while loop set up. I have the coding well enough to enter and store the first set of numbers but after that it ends the program. Using Dev-c++

These are the instructions:
1. You must use two different arrays, one for customer number, and one for sales. These are, in effect, parallel arrays.

2. You must use a "while" loop to gather customer number and sales. (I'm stuck here)

3. You must use a"for" loop to output the customer number and sales by customer.

Total number of customers I need to track is 4. Then the sales increase by 1000.

So basically to sum it up it looks like this
"How many customers do you want to track?" 4
"Enter the customer number." 1
"enter the sales for the customer" 1000
Program ends here with out me entering the rest of the information

Here is my code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
int printinfo
int addinfo(int cn, sales)
int main()
{
    int customers, customerNumber, sales;
   
    printf("How many customers do you want to track?");
    scanf("%d", &tracker);
    
}
   	while (tracker=0; counter<
    {  printf("Enter the customer number.");
       scanf("%d", &cn);
       printf("Enter the sales for the customer");
       scanf("%d", &sales);
       
    
       
       return 0;
    } 
Last edited on
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

#include <stdio.h>
#include
int printinfo
int addinfo(int customerNumber, sales);
int main(void)
{
    int customers[size_t] 
	int customerNumber [4]
	int sales[4000]
   
    printf("How many customers do you want to track?");
    scanf("%d", &customers);
    int addinfo(int customerNumber, sales)

	while(customer[4]{1,2,3,4},customersNumber[4]{1,2,3,4})
	{
		printf("Enter the customer number.");
		scanf("%d",&customerNumber);
		printf("Enter the sales for the customer.");
		scanf("%d",&sales);
	}

    
}


update to my code...still does samething but i am completely stumped
Last edited on
You may find the following useful: (Teaches for AND while loops)
Video 1: https://youtu.be/lf6WUg8a1xs
Video 2:
- Part 1: https://youtu.be/W_t-xn0rBWo
- Part 2: https://youtu.be/v0YWWcbEw-I

Basic Format:
while (condition == true) {}
or
while (condition == false) {}


An example of a while loop is:
1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;

int a = 4;
int b = 0;

while (b < a) {
    cout << "b = " << b << "\n";
    b++; // Will add 1 to b each time.
}


Output:
1
2
3
4
b = 0
b = 1
b = 2
b = 3


I hope this helps!

Edit: Also, for your code, there are a few issues I'm seeing:

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
#include <stdio.h>
int printinfo // <---- Needs a ";" at the end
// ^ If you're declaring a variable, I recommend putting it in main().
// Based off what I've learned so far, it's considered a good programming
// practice to avoid declaring global variables (variables outside of functions
// like main()) unless they are constants.
int addinfo(int cn, sales) // <--- Needs a ";" at the end
int main()
{
    int customers, customerNumber, sales;
   
    printf("How many customers do you want to track?");
    scanf("%d", &tracker);
    
} // <---- You ended the main() function here. Meaning your code below isn't in a function like it should be. So instead move this bracket to the very end, assuming you want all of the code to be in the main() function.
   	while (tracker=0; counter< // <-- Should be while (condition == something)  { ... }
    {  printf("Enter the customer number.");
       scanf("%d", &cn);
       printf("Enter the sales for the customer");
       scanf("%d", &sales);
       
    
       
       return 0;
    } 


More Correct Code:
(Note: There may still be issues, this is just based off what I know so far). Others could tell you if this is fully correct or not.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>

int printinfo(); // added the "();" assuming you want a function
int addinfo(int cn, int sales); // added the "int" for sales and the ";"

int main() {
    int customers, customerNumber, sales;
    int tracker = 0;
	
    printf("How many customers do you want to track?");
    scanf("%d", &tracker); // Not sure if you're using this correctly as I haven't used it myself. But I'm sure someone else knows.

    while (counter < ...) // Replace the "..." with what you want
    {
	printf("Enter the customer number.");
    	scanf("%d", &cn);
    	printf("Enter the sales for the customer");
    	scanf("%d", &sales);
    } // end of while loop

    return 0;
} // end of main() 


I strongly recommend bookmarking and taking a look at the following sites / YouTube playlists. They're sites I've found incredibly helpful while learning C++.

This Site for Tutorials, Help, and general information:
- http://www.cplusplus.com/

C++ Tutorials:
- https://www.youtube.com/playlist?list=PL6xSOsbVA1eYl_5aQUgxJYvJdzNBroGGy
- https://www.youtube.com/playlist?list=PL318A5EB91569E29A
- https://www.learncpp.com/
- https://www.youtube.com/playlist?list=PL68244A805BD16617

C++ Examples: (This is for once you know a bit more C++)
- https://www.youtube.com/playlist?list=PL6xSOsbVA1eaxY06L5ZZJfDZSohwO6AKY
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
int customers;
int customersNumber;
int sales;


int main()
{
	printf("how many customers do you want to track?");
	scanf("%d",&customers);
	
	while(customersNumber<customers)
	{printf("Enter the customer number.");
	scanf("%d",&customersNumber);
	printf("Enter the sales for the customer.");
	scanf("%d",&sales);
	}
	
}


New update it worked. Now How do I get step #3 to work
My comment provided info on how to do the for loop as well.

"You may find the following useful: (Teaches for AND while loops)
Video 1: https://youtu.be/lf6WUg8a1xs
Video 2:
- Part 1: https://youtu.be/W_t-xn0rBWo
- Part 2: https://youtu.be/v0YWWcbEw-I"
Topic archived. No new replies allowed.