Microsoft Visual Studio Wont output my code

Hello very new to using Visual Studio. I have Microsoft windows 10 64 bit, as well as the latest version of Visual Studio. I am trying to do a C++ homework assignment and when i press Control+F5, the command window opens up and says "Press any key to continue..." Which i do and press any key and it closes.

When i right click on the .cpp where my code is and compile it, i get this...

1>------ Build started: Project: ConsoleApplication9, Configuration: Debug Win32 ------
1>Skipping... (no relevant changes detected)
1>ConsoleApplication9.cpp
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
As well the code is not finished, not sure if that would cause this to not work.

 
Sounds like it's working fine. Sounds like the program runs and finishes.

What do you think it should be doing that it isn't doing?
Hello Repeater, I have a menu that should be displayed and that i should be able to select the different options. I am not seeing the opportunity to do that
Let's see the code; the contents of the file ConsoleApplication9.cpp.

Then we'll know if your code is fine, or if you're not building/running correctly.
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
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
//#include "stdafx.h"
//#include "targetver.h"
#include <iostream>
#include <iomanip>

using namespace std;
const int ROW = 5;
const int COL = 5;


void displayMenu();
int getInput();                 // added input function prototype
void displayArray(int myArray[][COL], int);  
void multiArray(int myArray[][COL], int);
void swapArray(int myArray[][COL], int);
void sum(int myArray[][COL], int);
void displayExit();              // added exit message function prototype
void displayError();             //added error message function protoype



int main() {
	int myArray[ROW][COL] = {
		{ 1,2,3,4,5 },
		{ -20,-40,-60,-80,-100 },
		{ 3,3,3,3,3 },
		{ 5,7,9,11,13 },
		{ -15,-25,-35,-45,-55 }
	};
	int choice = 0;
	do {                                   //Added the DO .. While Loop
		choice = getInput();
		displayMenu();
		switch(choice)
		{
			case 1:
				displayArray(int myArray, ROW);
				break;
			case 2:
				multiArray(int myArray, ROW);
				break;
			case 3:
				swapArray(int myArray, ROW);
				break;
			case 4:                                // added case 4 and 5
				sum(int myArray, ROW);
				break;
			case 5:
				displayExit();
				break;
			default:
				displayError();
				break;
		}
	}while (choice !=5)
}

void displayMenu()
{ 
	cout << "1. Display array" << endl;
	cout << "2. Multiply array by 3" << endl;
	cout << "3. Swap row 2 and row 3" << endl;
	cout << "4. Display sum of all elements" << endl;
	cout << "5. Exit" << endl;
}
int getInput() {                // added getInput function to gather the input from the user
	cout << "Input values 1 through 4, or 5 to exit program: " << endl;
	int choice;

	if (!(cin >> choise)) { 
		cin.clear();
		cin.ignore(numeric_limits<streamsize>::max(), '\n');
		choice = 0;
	}
	cout << endl;
	return choice;
}

void displayArray(int myArray[][COL], int rows) {  // fixed display function ( i think)
	cout << "Current Array: " << endl;
	for (int row = 0; row < rows; row++) {
		for (int col = 0; col < COLS; col++) {
			cout << setw(5) << right << myArray[ROW][COL] << " ";
		}
		cout << endl;
	}
	cout << endl;
}

void multiArray(int myArray[][COL], int rows)
	for (int row = 0; row < rows; row++) {
		for (int &val : myArray[row]) {
			val *= 3;
		}
	}
	cout << "Array multiplied by 3" << endl;
}

void swapArray(int myArray[][COL], int rows){

		
}

void sum(int myArray[][COL], int rows) { // added empty sum function to get back to


}
void displayExit() {
	cout << "The Program will now end" << endl;
}
void displayError() {
	cout << "Sorry, that is not a valid choice." << endl;
}

Last edited on
This code won't build. It won't compile.

displayArray(int myArray, ROW); is the first line that is wrong syntax.

Whatever you're building and running, it isn't this code.
Ok, i fixed all that code, and fixed the compiler errors. Now i am able to display the Menu, and when i enter 1, which is to display the array, this happens.

Main Menu
1. Display array
2. Multiply array by 3
3. Swap row 2 and row 3
4. Display sum of all elements
5. Exit

Current Array:
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
6870040 6870040 6870040 6870040 6870040
That's because you've programmed it to do that.

I can't tell you the exact line of code where you did it, because I can't see your code.
Topic archived. No new replies allowed.