Hi, all. I am very new to C++ and am close to losing my mind with the homework. We are asked to generate a multiplication table using a 'for statement'. User is to input a number between 1-12; the program will generate a multiplication table and should loop for no more than 15 times.
Sample table should look like this:
Multiplier Multiplicand Product
6 1 6
6 2 12
6 3 18
6 4 24
etc.
My code looks like this:
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
//*****MAIN*****
int main(void)
{
int choice, //output choice
val_1, //first number [multiplier]
x, //multiplicand
result; //x * val_1
char name[21]; //name
ofstream outfile; //to write to an output file
//*****INPUT SECTION*****
system ("cls");
cout << "Enter name: ";
cin.getline(name, 21);
cout << "Enter number between 1 through 12: ";
cin >> val_1;
//*****PROCESS SECTION*****
for ( int x = 1; x<=15; x++ )
{result = x * val_1;}
//OUTPUT SECTION
system ("cls");
cout << "Output Choice: 1 (Screen) 2 (File), choose 1 or 2: ";
cin >> choice;
if(choice==2)
outfile.open("f.multitable.dta");
else
outfile.open("con");
system ("cls");
outfile << setiosflags(ios::showpoint|ios::fixed)<< setprecision(2);
outfile << "Name: " << name << endl << endl << endl << endl;
outfile << setw(45) << "Multiplication Table" << endl;
outfile << setw(45) << "====================" << endl << endl;
outfile << setw(20) << "Multiplier" << setw(20) << "Multiplicand" << setw(20)<<"Product" << endl;
outfile << setw(20) << val_1 << setw(20) << x << setw(20) << result << endl;
outfile.close();
return 0;
}
Code formatted and tags added. -Narue
Any help would be most appreciated. It is due in class tomorrow [Friday, 4/22 at 7:00 p.m.] Thanks!!!!