So I've been stuck on this for a while. The assignment is to read in a certain input to a char array, do some stuff and then output it in a char array. But as I understand it, we cannot output each index using a loop. I was wondering how to go about this.
Here is my code so far for the program even though I know parts of it are wrong and you probably won't understand what I'm doing unless you read the requirements. Basically we are not allowed to do a LOT of things so that's why the code is how it is.
Code:
#include <iostream>
using namespace std;
const int MaxString = 73;
typedef char str[MaxString];
void main()
{
char command_step[25];
char motor_step[49];
char motor_program[73];
char output[81];
const str prompt = "MOTOR CONTROL PROGRAM GENERATOR";
const str command = "Command Step:";
const str motor = "Motor Step:";
const str program = "Complete Motor Program:";
const str hyphen = "------------------------------------------------------------------------";
const str equals = "========================================================================";
const str pound = "##";
const str invalid = "Invalid command step!";
int num = 0;
cout << prompt << endl << endl;
for (;;)
{
cout << command;
cin.getline(command_step, 25, '\n');
if ((command_step[0] == NULL) || (command_step[0] == ' '))
{
cout << hyphen << endl;
}
else if (command_step[0] == '0')
{
cout << motor << command_step << endl;
cout << hyphen << endl;
output[0] = command_step[0];
output[1] = command_step[1];
cout << command;
cin.getline(command_step, 25, '\n');
cout << hyphen << endl << endl;
if ((command_step[0] == NULL))
{
cout << program << output << pound << endl << endl << equals << endl << endl;
}
}
else if (command_step[0] == '1')
{
if (command_step[2] != '.')
{
cout << invalid << endl;
cout << hyphen << endl;
}
else
{
for (int i = 0; i < 2; i++)
{
motor_step[i] = command_step[i];
cout << motor_step[i];
}
//cout << motor << motor_step << endl;
//cout << hyphen << endl;
}
}
else
{
cout << invalid << endl;
cout << hyphen << endl;
}
}
}
You can ignore from the second else if on unless you get what I'm trying to do and can offer suggestions on the rest of the program. If you don't get what I'm trying to do then I'll try to explain better. Thanks in advance.