I'm using Microsoft Visual Studio. So far, this is my code.
#include <iostream>
using namespace std;
int main() {
int rows;
int cols;
int num;
int size = 3;
rows = 0;
while (rows < size) {
cols = 0;
while (cols < size) {
cols = (cols + 1);
cout << cols << " | " << endl;
}
rows = (rows + 1);
cout << endl;
}
system("pause");
return 0;
}
I'm getting confused on how to add the totals and how to fix the numbers so that they show up the correct way. When I added that cout << cols << " | " << endl; line, it made my numbers appear in all one column instead of 3. If anyone can help me fix this up soon, I would really appreciate it. I'm stuck on how to finish it. Thank you!
Not sure if the system("pause") is really going to make that much of a difference in the grand scheme of things. Okay so I figured out that I need to add in an array and add more in to try and complete this. I have this so far:
#include <iostream>
using namespace std;
int main() {
int cols;
int num[9];
int number;
int counter = 0;
int rows = 0;
int size = 3;
while (counter < 9) {
cout << "Enter a number between 0 and 100: ";
cin >> number;
while ((number < 0) || (number > 100)) {
cout << "Please enter a number between 0 and 100: ";
cin >> number;
}
num[counter] = number;
counter = (counter + 1);
}
while (rows < size) {
cols = 0;
while (cols < size) {
cols = (cols + 1);
cout << cols << " | ";
}
rows = (rows + 1);
cout << endl;
}
system("pause");
return 0;
}
Obviously it's still not giving me the output I need but I keep getting stuck just when I think I have it figured out. Any suggestions? Thanks!
Wow thank you! I changed my coding around a little bit. I just need to figure out how to get the totals at the bottom of each column and at the end of each row. I'd like to still keep the same code I have (obviously with some changes to it). The asterisks are where the totals are supposed to be. Thanks
#include <iostream>
using namespace std;
int main() {
int cols = 0;
int num[9];
int number;
int counter = 0;
int rows = 0;
int size = 3;
int rowsum = 0;
while (counter < 9) {
cout << "Enter a number between 0 and 100: ";
cin >> number;
while ((number < 0) || (number > 100)) {
cout << "Please enter a number between 0 and 100: ";
cin >> number;
}
num[counter] = number;
counter = (counter + 1);
}
int counter2 = 0;
while (counter2 < 9) {
cout << num[counter2] << " | ";
if ((counter2 + 1) % 3 == 0) {
cout << " = *" << endl;
}
counter2++;
}
cout << "--|--|--" << endl;
rowsum += num[cols+rows*3];
cin >> rowsum;
cout << rowsum;
cout << "* ";
cout << "* ";
cout << "* " << endl;
system("pause");
return 0;
}