473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

help with functions.

just learning c++. trying out this small routine to demonstrate how to
center text on the screen. It's a function called "int cent(int)"
doesn't work for me. could you take a look for me.

thanks
Mark
/* This is my main menu program */
#include <iostream.h>

//FUNCTION PROTOTYPES

int cent(int );
void burger();
void fries();
void frappe();
void hotdog();
void icecream();
void coke();
void pepsi();

//BEGIN MAIN

int main()
{

//int cent(int );
int name = 0 ;


cout
<<"1=burger\n"<<"2=fries\n"<<"3=frappe\n"<<"4=hotd og\n"<<"5=icecream\n"<<"6=coke\n"<<"7=pepsi\n"<<
endl;
cin >> ws;
cin >> name;

if (name==1)
{

cent(32);cout<<burger();
}
else
if(name==2){

fries();}
else
if(name==3)
frappe();
else
if(name==4)
hotdog();
else
if(name==5)
icecream();
else
if(name==6)

coke();
else

if(name==7)

pepsi();
else

cout<<"Not on the menu!\n";


return 0;

}

void burger()
{
cout<<"Thank you for ordering a burger\n";

}

void fries()
{

cout<<"Thank you for ordering fries\n"<<endl;
}
void frappe()
{
cout<<"Thank you for ordering a
frappe\n";
}
void hotdog()
{
cout<<"Thank you for ordering a
hotdog\n";
}
void icecream()
{
cout<<"Thank you for ordering an
icecream\n";
}
void coke()
{
cout<<"Thank you for ordering a
coke\n";
}
void pepsi()
{
cout<<"Thank you for ordering a
pepsi\n";
}

int cent(int len)
{
int j;

j = 39 - (len/2);

for(int i = 1; i < (j+1); i++)

cout << "";

return 0;
}
Jul 19 '05 #1
2 2030
vinhkan wrote:
just learning c++. trying out this small routine to demonstrate how to
center text on the screen. It's a function called "int cent(int)"
doesn't work for me. could you take a look for me.

thanks
Mark
/* This is my main menu program */
#include <iostream.h>

//FUNCTION PROTOTYPES

int cent(int );
void burger();
void fries();
void frappe();
void hotdog();
void icecream();
void coke();
void pepsi();

//BEGIN MAIN

int main()
{

//int cent(int );
int name = 0 ;


cout
<<"1=burger\n"<<"2=fries\n"<<"3=frappe\n"<<"4=hotd og\n"<<"5=icecream\n"<<"6=coke\n"<<"7=pepsi\n"<<
endl;
cin >> ws;
cin >> name;

if (name==1)
{

cent(32);cout<<burger();
}
else
if(name==2){

fries();}
else
if(name==3)
frappe();
else
if(name==4)
hotdog();
else
if(name==5)
icecream();
else
if(name==6)

coke();
else

if(name==7)

pepsi();
else

cout<<"Not on the menu!\n";


return 0;

}

void burger()
{
cout<<"Thank you for ordering a burger\n";

}

void fries()
{

cout<<"Thank you for ordering fries\n"<<endl;
}
void frappe()
{
cout<<"Thank you for ordering a
frappe\n";
}
void hotdog()
{
cout<<"Thank you for ordering a
hotdog\n";
}
void icecream()
{
cout<<"Thank you for ordering an
icecream\n";
}
void coke()
{
cout<<"Thank you for ordering a
coke\n";
}
void pepsi()
{
cout<<"Thank you for ordering a
pepsi\n";
}

int cent(int len)
{
int j;

j = 39 - (len/2);

for(int i = 1; i < (j+1); i++)

cout << ""; |
You've got an empty string here ---------------+
which is not going to output anything. Change to ' '. (with a space)

return 0;
}

Jul 19 '05 #2
> just learning c++.

Get a good book (and throw away the one you are using right now).
trying out this small routine to demonstrate how to
center text on the screen. It's a function called "int cent(int)"
doesn't work for me. could you take a look for me. /* This is my main menu program */
Good to know.

Too many comments is like not enough.

#include <iostream.h>
Non standard :

# include <iostream>

using std::cout;
using std::cin;
using std::endl;
//FUNCTION PROTOTYPES

int cent(int );
void burger();
void fries();
void frappe();
void hotdog();
void icecream();
void coke();
void pepsi();

//BEGIN MAIN

int main()
{

//int cent(int );
int name = 0 ;
Do you think it makes sense to have an integer variable called 'name' ?
Make up _good_ names for your variables.

cout
<<"1=burger\n"<<"2=fries\n"<<"3=frappe\n"<<"4=hotd og\n"<<"5=icecream\n"<<"6=
coke\n"<<"7=pepsi\n"<< endl;
Try to indent your code better next time :

cout << "1 = burger\n"
<< "2 = fries\n"
<< "3 = frappe\n"
<< "4 = hotdog\n"
<< "5 = icecream\n"
<< "6 = coke\n"
<< "7 = pepsi\n"
<< endl;
cin >> ws;
What is 'ws' ?
cin >> name;
What if the user enters letters or garbage?
if (name==1)
Here would be a good time to make a switch :

switch ( name )
{
case 1 :
{
cent(32);
cout << burger();
break;
}

case 2 :
{
fries();
break;
}

// ...

};

<snip>
int cent(int len)
{
int j;

j = 39 - (len/2);
Not portable .. :)

for(int i = 1; i < (j+1); i++)
two things : 1) increment 'j' before the loop instead of adding one on each
turn and 2) prefer ++i when you are not using the return value.
cout << "";
And to get to your problem, this outputs nothing on the screen. What you
want is

cout << " ";
return 0;


What is that return value for ?
Jonathan
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: gomerpyl3 | last post by:
I am trying to make a small system to record details for a small video / DVD shop - approx 200 members @ the mo I wanted it to be able to do the following: Check out a video / DVD Return...
7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: Paminu | last post by:
I have made a lot of helping functions that I would like to have in a seperate file. I have tried putting them in a file "functions.c". I then have the file "myprogram.c" that contains some...
1
by: R-D-C | last post by:
Hi, I have a client who uses a web service containing about 100 functions. I made a couple of changes to four functions, tested it (fine), deployed to VMWare virtual machine (still working...
8
by: metaperl | last post by:
Hi, I would like an IDE that shows me all methods and functions I can call on a particular data item. For instance, iter() can be called on any sequence, but it is not a method. Nonetheless,...
16
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
5
by: cherriecheng88 | last post by:
hi...did anyone know how to do this assignment? cuz, i have run out of time really need ppls help me out thank you if you know it... Blackjack For the third assignment you will write a program...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.