Functions

HELP PLEASE!

Problem: Define the functions called within the main function. Do NOT edit the main function.

int main(){
int num,choice;
do{
num=askNum();//asks and returns a number
menu(); //displays the menu
cin>>choice;
switch (choice){
case 1: dispUpSeries(num);//display 1 to number
break;
case 2: dispDownSeries(num);//display number to 1
break;
case 3: dispGoodByeMesg();
break;
default: dispErrorMesg();//display error message
}
}while(choice!=3);
return 0;
}

MY CODE: IT WORKS BUT THE OUTPUT IS DIFFERENT

#include <iostream>
using namespace std;

int askNum();
void menu();
void dispUpSeries(int x);
void dispDownSeries(int y);
void dispErrorMesg();
int main ()
{
int num,choice;

cout << "-----------------------------" << endl;
do {
menu();
cin >> choice;
num= askNum();
switch (choice) {
case 1: dispUpSeries(num); //display 1 to number
break;
case 2: dispDownSeries(num); //display number to 1
break;
default: dispErrorMesg(); //display error message
}
}while(choice!=3);
return 0;
}

int askNum() {
int num;
cout << "Type a number: ";
cin >> num;
return num;
}

void menu() {
cout << "***********Menu***********" << endl;
cout << "[1]Display Forward Series" << endl;
cout << "[2]Display Downward Series" << endl;
cout << "[3]Exit Program" << endl;
cout << "**************************" << endl;

cout << endl << "Type number of choice: ";
}
void dispUpSeries(int x) {
cout << endl;
int i=1;
while(i>8);
i++;
cout << "Upward Series from 1" << x << "to 8" << ":" ;
}

void dispDownSeries(int y) {
cout << endl;
int j=1;
while(j<6);
j--;
cout << "Downward Series from" << j <<"to 1" << ":" ;
}

void dispErrorMesg() {
cout << "Error!Type 1, 2, or 3 only." << endl;
}

AND THIS SHOULD BE THE OUTPUT FOR IT (SAMPLE DIALOGUE):

-----------------------------------------
Type a number: 6
***********Menu***********
[1]Display Forward Series
[2]Display Downward Series
[3]Exit Program
**************************
Type Number of Choice: 2
Downward Series from 6 to 1: 6 5 4 3 2 1
-----------------------------------------
Type a number: 8
***********Menu***********
[1]Display Forward Series
[2]Display Downward Series
[3]Exit Program
**************************
Type Number of Choice: 1
Upward Series from 1 to 8: 1 2 3 4 5 6 7 8
-----------------------------------------
Type a number: 8
***********Menu***********
[1]Display Forward Series
[2]Display Downward Series
[3]Exit Program
**************************
Type Number of Choice: 5
Error!Type 1, 2, or 3 only.
-----------------------------------------
Type a number: 8
***********Menu***********
[1]Display Forward Series
[2]Display Downward Series
[3]Exit Program
**************************
Type Number of Choice: 3
Good Bye! Thank you for using this program.

please use
[code][/code]

Last edited on
Do NOT edit the main function.

Your code uses a different main function. Delete your main and copy/paste the required main function into your code.

Next you will find that you're missing the dispGoodByeMesg() function.

Your dispUpSeries() and dispDownSeries() functions don't work right. dispUpSeries() should display the numbers from 1 to x (the parameter to the function). dispDownSeries() should display the numbers from y (the parameter) down to 1. Use a "for" loop for these.
Topic archived. No new replies allowed.