GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Mar-2009, 14:12
ReitaBassist ReitaBassist is offline
Awaiting Email Confirmation
 
Join Date: Feb 2009
Location: Asia
Posts: 8
ReitaBassist is on a distinguished road

Stuck in these two similar programs


This is what I've already done:

CPP / C++ / C Code:
#include <stdio.h>
#include "simpio.h"
#include "genlib.h"
main()
{
int base, power, mul;
printf("Enter the base");
base=GetInteger();
printf("Enter the power");
power=GetInteger();
while(base!=0)
{
Objective is to write a program that calculates the power of a number by using the multiplication sign.

Stuck with the same part of the next one:
CPP / C++ / C Code:
#include <stdio.h>
#include "simpio.h"
#include "genlib.h"

main()
{
      int num, max, min;
      
      printf("Signal the end of your list with 0.\n");
      max=0; min=0;
      printf("Enter first number");
      num=GetInteger();
      while(num!=0)
      {

Objective: write a program that finds the maximum and minimum number of a list.

I just got a little stuck with what should go after the "{". Any help?
-ty
  #2  
Old 30-Mar-2009, 14:28
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,311
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Stuck in these two similar programs


Why don't we take them one at a time? Get the first one under your belt, and maybe you will gain some insight that will help with the second one (and the many, many programs to follow).

Quote:
Originally Posted by ReitaBassist
...
Objective is to write a program that calculates the power of a number by ...multiplication

I would formulate the problem as follows:

Code:
Declare integer variables for base, power and result. Get the "base" integer from the user. (Make sure it is positive.) Get the "power" integer from the user. (Make sure it is not negative.) Set "result" equal to 1 Peform the following "power" times: result = result * base

Note that a useful idiom (and probably the most used construct) in C and C++ if you want to do something n times is
CPP / C++ / C Code:
    int i;
    for (i = 0; i < n; i++) {
        /* Do something */
    }

I mean, there are other looping constructs, but if I know how many times I want to do something, I (usually) just use a "for" loop to count the iterations.

Regards,

Dave
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to interact with other programs? Soybeanio C++ Forum 2 25-Aug-2008 14:49
Affiliate Programs Directory - over 1700 programs including contexual ads, CPM,... john924 Member Announcements, Advertisements & Offers 1 29-Jul-2008 19:43
2-tiered CPM Affiliate Programs $$ john924 Advertising & Affiliates Forum 4 21-Sep-2004 14:31
HTML editors & Web Design Programs pcxgamer Web Design Forum 15 19-Mar-2003 06:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:42.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.