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 05-Dec-2007, 14:34
herceca herceca is offline
New Member
 
Join Date: Dec 2007
Posts: 6
herceca is on a distinguished road

help with program please


we are supposed to enter a number of stores (i.e. 9 stores) and make a bar graph based on every 100$ sale
stores:9(random number i entered just to show example
store 1: 400$(random number i entered just to show example)
store 1: ****
store 2: 900$
store 2: *********
store 3: 500$
store 3: *****
store 4: 1000$
store 4: **********
and so on...

it just doesnt seem to work

CPP / C++ / C Code:
int main ( )
{

int store=0;
int total=0;
int stores=0;
int storecounter=0;

cout <<"How many stores are there?: ";
cin >> stores;
while (storecounter<=stores)
{
cout << "Enter todays sales for store:";
cin >> store;
while (store<0)
{
cout << "Wrong number, try again: ";
cin >> store;
}
cout << "Store: "<< endl;
}
for (total=100;total<=store;total=total+100)
{
cout << "*";
}
cout << endl;



return 0;
}
Last edited by LuciWiz : 05-Dec-2007 at 14:44. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 05-Dec-2007, 15:06
fakepoo fakepoo is online now
Regular Member
 
Join Date: Oct 2007
Posts: 478
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: help with program please


I think it would be simpler if you store the values for each store in an array (or vector). This way, you could find the largest value and work your way down from there. Here's how I would do it:

CPP / C++ / C Code:
int main ( )
{ int* stores=NULL;
  int  n; // number of stores
  int i;

  // Get user input
  cout <<"How many stores are there?: ";
  cin >> n;

  // Create an array to hold all of the values
  if(n > 0) stores = new int[n];

  // Get more user input
  for(i=0;i<n;i++)
  { cout << "Enter todays sales for store #" << i+1 << ": ";
    cin >> stores[i];
    cout << endl;
  }  

  // Create bar graph
  // Step 1: Find the highest sales of the group, round it down to the nearest 100, and put it into a variable (we'll call it high)

  // Step 2: 
  for(i=high;i>0;i-=100)
  { // loop through all of the stores and if it has a value greater than i, print a *, otherwise print a space
    
    cout << endl;
  }

  // delete the array
  if(n > 0) delete[] stores;

  return 0;
}
  #3  
Old 05-Dec-2007, 15:45
herceca herceca is offline
New Member
 
Join Date: Dec 2007
Posts: 6
herceca is on a distinguished road

Re: help with program please


thanks, although i have trouble getting the bargraph to work correctly
  #4  
Old 06-Dec-2007, 01:56
inevitable inevitable is offline
Junior Member
 
Join Date: Nov 2007
Posts: 53
inevitable is on a distinguished road

Re: help with program please


CPP / C++ / C Code:
#include <iostream.h>
#include <conio.h>
int main ( )
{

int store=0;
int total=0;
int stores=0;
int storecounter=0;

cout <<"How many stores are there?: ";
cin >> stores;
while (storecounter<stores)
{
	cout << "Enter todays sales for store:";
	cin >> store;
	if(store<0||store>10000)
	{
	cout << "Wrong number, try again: ";
	cin >> store;
	}
	cout << "Store: ";
	for (total=100;total<=store;total=total+100)
	{
		cout << "*";
	}
	cout <<endl;
	storecounter++;
}
cout << endl;
return 0;
}
Last edited by admin : 07-Dec-2007 at 09:43. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
 
 

Recent GIDBlogMeeting the local Iraqis 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
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
Text-Based Roulette Game mfm1983 C++ Forum 5 29-Nov-2006 12:20
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 03:48
Pipeline freeze simulation darklightred C++ Forum 6 27-Jul-2006 19:37
How to read particular memory location ? realnapster C Programming Language 10 10-May-2006 09:11

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

All times are GMT -6. The time now is 13:03.


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