Loop

How and where to place a For loop so that Weekdays in below program automatically get its concerns value and then print it out on screen.. E.G

Sunday = 10
monday = 20
tuesday = 30 and so on,



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include <iostream>

using namespace std;


 int main()
 {
 enum WeekDays { Sun, Mon, Tue, Wed, Thu, Fri, Sat, DaysInWeek };

 int ArrayWeek[DaysInWeek] = { 10, 20, 30, 40, 50, 60, 70 };

 for (int i=0; i<7; i++){

 cout << "The value at Tuesday is: " << i[ArrayWeek] <<endl;
 }

 return 0;
 }
Well, I don't know what enum is and I don't know why you have DaysInWeek as a part of it and then using it for your ArrayWeek before giving it a value, so.....

This is what I have (sorry if it is not what you wanted accomplished!):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>

using namespace std;


 int main()
 {
	 
	 string WeekDays[8] = {"Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat", "Days In Week"} ;

	 int ArrayWeek[7] = { 10, 20, 30, 40, 50, 60, 70 };

	 for (int i=0; i<7; i++){

 cout << "The value at "<<WeekDays[i]<<" is: " << ArrayWeek[i] <<endl;
 }

 return 0;
 }
Topic archived. No new replies allowed.