jrice528 20 Light Poster

In my program I am using the do-while loop to go through program..

my question is how do I loop the program without the do-while loop...
rather that when the user enters menu number 0, it quits the program...
Teacher uses a script to grade the programs and on hsi example it just runs over and over without it asking "continue?"

any advice?

#include <iomanip>
#include <cstdlib>
#include <iostream>
#include "RetailItem.h"
#include "RetailStore.h"

using namespace std;
const unsigned W = 20;


int main(int argc, char *argv[])
{
    RetailItem r;
    RetailStore s;
    char z;

s.setZero();

do
{
   cout<<"This is Programming Assignment #7"<<endl;
   cout<<"THE RETAIL STORE MANAGER"<<endl;
   cout<<"By Jeremy Rice of CSCI 111"<<endl;
   cout<<"Please choose from the following options"<<endl;
   cout<<"\n 1 - Display total inventory"<<endl;
   cout<<"\n 2 - Search for an item"<<endl;
   cout<<"\n 3 - Add a new item to inventory"<<endl;
   cout<<"\n 4 - Sell/Subtract units of an item"<<endl;
   cout<<"\n 5 - Buy/Add units of an item"<<endl;
   cout<<"\n 6 - Change description of an item"<<endl;
   cout<<"\n 7 - Delete an item from the inventory"<<endl;
   cout<<"\n 8 - List items that need ordered"<<endl;
   cout<<"\n 0 - Quit"<<endl;
   cout<<"Your choice: ";
   cin>>s.choice;

// IF CHOICE ONE IS ENTERED
// DISPLAY ALL INVENTORY

   if (s.choice == 1)
      {
       cout<<"Item"<<setw(20)<<"Description"<<setw(20)<<"Units on Hand";
       cout<<setw(15)<<"Price ($)";
       cout<<setw(15)<<"Subtotal($)"<<endl;
       s.getStoreInventory();
      }

//IF CHOICE TWO IS ENTERED
//SEARCH ITEM BY ITS DESCRIPTION

   if (s.choice == 2)
      {
       s.getSearch();
      }

// IF CHOICE THREE IS ENTERED
// ADD INVENTORY TO THE STORE

   if (s.choice == 3)
      { …
jrice528 20 Light Poster

Is there a function in C++ where a string can be held in a Unsigned array?

jrice528 20 Light Poster

Ok, I am setting all elements in the array to 0...
If all elements are 0, i want it to display "No inventory"
if there is something in the element, i want to display only its contents..

Heres the code, how do I make it display No Inventory only when all are 0, not every single 0.

for (int i = 0; i < size; i++)             
{
   item[i] = 0;
}
for (int j = 0; j < size; j++)
    if (item[j] == 0)
    cout<<"No Inventory";
    else 
         cout<<item[j]<<endl;
}
jrice528 20 Light Poster

In the retailitem.cpp I need to beable to increment x,y and z. So that is displays the next item. Heres what the code should output

Descriptio   Units On Hand	Unit Price ($)
Item #1	Jacket	        12	                     59.95
Item #2	Jeans	        40	                     34.95
Item #3	Shirt	        20	                     24.95

Heres the code I have...

main.cpp

#include <cstdlib>
#include <iostream>
#include "RetailItem.h"
#include <iomanip>
using namespace std;
const unsigned W = 20;

int main(int argc, char *argv[])
{
    RetailItem r;
 
cout<<setw(W)<<"Description"<<setw(W)<<"Units on Hand"<<setw(W)<<"Price ($)"<<endl;
cout<<endl;
cout<<"Item #1";
cout<<setw(10)<<r.getDescription();
cout<<setw(15)<<r.getUnitsOnHand();
cout<<setw(25)<<r.getPrice()<<endl;
cout<<"Item #2";
cout<<setw(10)<<r.getDescription();
cout<<setw(15)<<r.getUnitsOnHand();
cout<<setw(25)<<r.getPrice()<<endl;
cout<<"Item #3";
cout<<setw(10)<<r.getDescription();
cout<<setw(15)<<r.getUnitsOnHand();
cout<<setw(25)<<r.getPrice()<<endl;
    
    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

retailitem.h

#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <stdlib.h>

using namespace std;

class RetailItem   

{
      
              
      public:
             static const unsigned SIZE = 100;
             static const unsigned SIZE1 = 100;
             static const unsigned SIZE2 = 100;
             RetailItem();
             void setDescription();
             void setUnitsOnHand();
             void setPrice();
             string getDescription();
             double getUnitsOnHand();
             double getPrice();
             
             
      private:

              string description;
              unsigned unitsOnHand;
              double price;
              double x,y,z;
              double p[SIZE];
              string d[SIZE1];
              double oh[SIZE2];
              
              
              
};

retailitem.cpp

#include <cstdlib>
#include <iostream>
#include <string>
#include "RetailItem.h"

using namespace std;


RetailItem::RetailItem()
{
}

double RetailItem::getPrice()
{
     x = 0;
     p[1] = 59.95;
     p[2] = 34.95;
     p[3] = 24.95;
     x++;
     return p[x];
     
}

string RetailItem::getDescription()
{
       y=0;
       d[1] = "Jacket";
       d[2] = "Jeans";
       d[3] = "Shirt";
       y++;
       return d[y];
}


double RetailItem::getUnitsOnHand()
{
       z=0;
       oh[1] = 12;
       oh[2] = 40;
       oh[3] = 20;
       z++;
       return oh[z];
}
jrice528 20 Light Poster

Ok, so this is what i have... sorry for the ignorance, but i am slowly getting it..

if i typed "prime 45 70"
the program rightly displays primes between 45 and 70..
if I type "prime" the program rightly displays who it was created by and how to use it...except with a "memory fault"at end.

If I type " prime 6" I just get "memory fault" it should display if that number is prime or not..

What am i doing wrong to get that memory fault.. That is the last thing I need to do with this program, again sorry, but thank you for patience and your help.

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;
const unsigned W = 10;

int main(int argc, char *argv[])
{
   const unsigned long arraySize = 1000000;
   bool a[arraySize];
   unsigned long num1;
   unsigned long num2;
   unsigned long num3;
   unsigned long counter = 0;
   unsigned long primes = 0;
   char z;
   unsigned long answer = 0;
  
//Initializing elements to 1 
        
for (int i = 0; i < arraySize; i++)             
{
   a[i] = 1;
}       
// For array subscript 2, all elements beyond 2 in the array that
// are multiples of 2 will be set to zero; for array subscript 3, 
// all elements beyond 3 in the array that 
// are multiples of 3 will be set to zero


for (int i = 2; i * i < arraySize; i++)
{
    if (a[i])
       for (int …
jrice528 20 Light Poster

OK, I finally figured out command line arguments... my program is called prime, in the console i need to type "prime 7" and the program will tell me if its a prime or not.

heres my code:

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <stdlib.h>

using namespace std;


int main(int argc, char *argv[])
{
   const unsigned long arraySize = 1000000;
   bool a[arraySize];
   unsigned long num1;
   unsigned long num2;
   unsigned long num3;
   unsigned long counter = 0;
   unsigned long primes = 0;
   char z;
   unsigned long answer = 0;
  
//Initializing elements to 1 
        
for (int i = 0; i < arraySize; i++)             
{
   a[i] = 1;
}       
// For array subscript 2, all elements beyond 2 in the array that
// are multiples of 2 will be set to zero ; for array subscript 3, 
// all elements beyond 3 in the array that 
// are multiples of 3 will be set to zero


for (int i = 2; i * i < arraySize; i++)
{
    if (a[i])
       for (int j = i + i; j < arraySize; j += i)
          a[j] = 0;
} 
// if user enters more than 3 numbers or 0 numbers
// program should output useful information
// and title and author

if ((argc > 4) || (argc == 1))
{
 cout<<"This is Programming Assignment #5"<<endl;
 cout<<"THE SIEVE OF ERATOSTHENES"<<endl;
 cout<<"by Jeremy Rice"<<endl;
 cout<<endl;
 cout<<"Usage:"<<endl;
 cout<<"\tprime num1 - determines if num1 is a prime"<<endl;
 cout<<"\tprime num1 num2 - displays primes between numbers."<<endl;
}

// …
jrice528 20 Light Poster

What exactly does this mean??

Your program must determine the user-specified lower bound and upper bound by using command-line arguments. You will need to use the strtoul() function (from the cstdlib header) to convert command-line arguments to int values.

jrice528 20 Light Poster

Ok, i have this program
It determines if the number entered is a prime or not.
I did that, posted it, and now i need to do this:
Determine and print the prime numbers between a user-specified lower bound and user-specified upper bound.

Read all through my text and browsed all over the net... How exactly would you do that? Is there a certain function?
This isnt homework, well, its extra credit while over break.

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;


const unsigned W = 10;


int main(int argc, char *argv[])
{
   const unsigned long arraySize = 1000000;
   bool a[arraySize];
   unsigned long b, x;
   unsigned long counter = 0;
   unsigned long primes = 0;
   char z;

cout<<"This program is programming assignemnt #5."<<endl;
cout<<"THE SIEVE OF ERATOSTHENES."<<endl;
cout<<"By Jeremy Rice of CSCI 111."<<endl;


//Initializing elements to 1 
        
for (int i = 0; i < arraySize; i++)             
{
   a[i] = 1;
}       
// For array subscript 2, all elements beyond 2 in the array that
// are multiples of 2 will be set to zero ; for array subscript 3, 
// all elements beyond 3 in the array that 
// are multiples of 3 will be set to zero


for (int i = 2; i * i < arraySize; i++)
    if (a[i])
       for (int j = i + i; j < arraySize; j += i)
           a[j] = 0;      
                                           

// print all subscripts set to 1
do
{
 cout<<"Prime > ";
 cin>>b; …
jrice528 20 Light Poster

nvm nvm I figured it out!

jrice528 20 Light Poster

Ok, tried to format a little better, added some comments, but its not alot hehe.. anyways, my prog has a ways to go, but the last part I know how to do, its just taking out the prime numbers, and displaying them. I figured the counter out I think. I just need help with the formula to keep checkin like... take out multiples of 3, 4, 5 and so one, up until the user specified number.

Thanks for the help you have already provided, i appiciate it alot. Really new to programming, and never uesd arrays before.

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;


const unsigned W = 10;

int main()
{
    const unsigned arraySize = 5;
    int a[arraySize];
    unsigned b;
    unsigned c;   
    unsigned d;
    unsigned counter = 0;


cout<<"This program is programming assignemnt #5."<<endl;
cout<<"THE SIEVE OF ERATOSTHENES."<<endl;
cout<<"By Jeremy Rice of CSCI 111."<<endl;

//Initializing all elements to 1
          
for (int i = 0; i < arraySize; i++)
{
         a[i] = 1;
// Initializing all elements divisable by 2, to 0
for (int j = 0; j < arraySize; j = j+2)
    {
         a[j+1] = 0;
    }

}

cin>>b;
for (int j = 2; j < b; j++)
{
    if (a[j] == 1)
    {
       counter++;
       cout<<counter<<endl;
    } 
    else
        counter++; 
}

        
system("pause");
return 0;
}
jrice528 20 Light Poster

Are you talking something along the lines like this, to eliminate all the numbesr divisible by two..


if so, my question is how would i print the subscript of the array if it is set to 1? again ty for your help

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

void prime_num(int);
const unsigned W = 10;

int main()
{
    const unsigned arraySize = 5;
    int a[arraySize];
    unsigned b;
    unsigned c;   
    unsigned d;
    
cout<<"This program is programming assignemnt #5."<<endl;
cout<<"THE SIEVE OF ERATOSTHENES."<<endl;
cout<<"By Jeremy Rice of CSCI 111."<<endl;


       for (int i = 0; i < arraySize; i++)
{
    a[i] = 1;
    for (int i = 2; i < arraySize; i += 2)
{
    a[i] = 0;
  
}
}


cin>>b;
for (int j = 0; j < b; j++)
cout<<a[j];

        
system("pause");
return 0;
}
jrice528 20 Light Poster

I am working on homework, and been doing this assignment with absolutely no luck, i am in need of major help.

This is the assignment. Using an array, initialize all elements in the array to 1. Starting with array subscript 2, every time an array element is found whose value is 1, loop through the remainder of the array and set to zero every element whose subscript is a multiple of the subscript for the element with value 1. all elements beyond 2 in the array that are multiples of 2 will be set to zero (subscripts 4, 6, 8, 10, etc.);


this is my code, i have initialized all elements in the aray to 1. I need MAJOR help with a formula to determine if its prime, and set everything else to a 0. I have been working on this one part for 3 days and i finally gave in and need help... Any help is really appiciated!!!

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

void prime_num(int);
const unsigned W = 10;

int main()
{
    const unsigned arraySize = 5000;
    int a[arraySize];
    unsigned b;
    unsigned c;   
    unsigned d;
    
cout<<"This program is programming assignemnt #5."<<endl;
cout<<"THE SIEVE OF ERATOSTHENES."<<endl;
cout<<"By Jeremy Rice of CSCI 111."<<endl;

for (int i = 2; i < arraySize; i++)
{
    a[i] = 1;   
}

for (int j =2; j < b; j++)
              



system("pause");
return 0;
}
jrice528 20 Light Poster

Requirement for homework is a double calcScore function, and i think it will work for this program because the number will never be larger than 10...

jrice528 20 Light Poster

seems to run ok when i go this

avg = (float)(s.getSum() - s.getMax() - s.getMin()) / 3.0);

i can compile it on my schools unix server without any problems and returns the decimal at the end... that would work or like later will someone mess up haha

jrice528 20 Light Poster

without messing with the class, cause i cant modify it , i was wondering if there is a way to return thefunction calcscore as a float. I cant modify the class, where i call the function

"This contestants average score was..." it always just returns a .000 is there a way to pass it as a float without messin with the class?

//Jeremy Rice
// CSCI 111
// FALL 2007

#include <iomanip>  // for setw(), setprecision()
#include "Stat.h"
#include <iostream>
using namespace std;
//Function Prototypes
void getJudgeData(int &);
double calcScore(Stat s);

const unsigned W=25; // argument for setw()
const unsigned P= 3; // argument for setprecision()

void showStat( Stat ); // displays statistics from Stat object

int main()
{
    //Initilizing variables and class
    Stat s;
    
    int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
    int x = 1;
    double total = 0;
    double winner = 0;
    double contest;
    char z;

cout << "This program assignment number #4"<<endl;
cout<< "THE NEXT AMERICAN IDOL"<<endl;
cout<< "By Jeremy Rice of CSCI 111"<<endl;
cout<<endl;

cout<< "Please enter your scores below!"<<endl;
//Ask each of the Judges for a score from 1-10
//anything less than 0 and greater than 10 will not be accepted

 
do
 {    
      s.reset();
cout<< "Enter contestant #"<<x<< " scores!"<<endl;

cout<<setw(W)<<"\tJudge #1 what is your score [0...10] : ";
               getJudgeData(score1);  //calling function for score1
               s.setNum(score1);
cout<<setw(W)<<"\tJudge #2 what is your score [0...10] : ";
               getJudgeData(score2);  //score2
               s.setNum(score2);
cout<<setw(W)<<"\tJudge #3 what is your score [0...10] : ";
               getJudgeData(score3); //score3
               s.setNum(score3);
cout<<setw(W)<<"\tJudge …
Ancient Dragon commented: Thanks for using code tags correctly :) +20
jrice528 20 Light Poster

Wow awesome i finally got it, thanks for the help !!! like majorly couldnt of done without help.
I do have one last question. What do I do to start a loop for it all? from the part "is there another contestant?" if i press Y how would i loop that back to the begining?

#include "Stat.h"
#include <iostream>
using namespace std;

void getJudgeData(int &);
double calcScore(Stat s);

int main()
{
    Stat s;
    
    int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
    int x = 1;
    int winner;


	cout << "This program assignment number 4 was created by Jeremy Rice" << endl;
	cout<<  "The Next American Idol!!!"<<endl;
    cout<< "Please enter your scores below!"<<endl;
     

  cout<< "Enter contestant #"<<x<< " scores!"<<endl;
  cout<<"Judge #1 what is your score: ";
               getJudgeData(score1);
               s.setNum(score1);
  cout<<"Judge #2 what is your score: ";
               getJudgeData(score2);
               s.setNum(score2);
  cout<<"Judge #3 what is your score: ";
               getJudgeData(score3);
               s.setNum(score3);
  cout<<"Judge #4 what is your score: ";
               getJudgeData(score4);
               s.setNum(score4);
  cout<<"Judge #5 what is your score: ";
               getJudgeData(score5);
               s.setNum(score5);
  
  cout<<"Talent score for contestant #"<<x<<" is: ";
                calcScore(s);
                x++;
  cout<<"Is there another contestant? (Y/N)"<<endl;

  
    system("pause");
	return 0;
}



void getJudgeData(int &getNum)
{
     Stat s;
    cin>> getNum;
     return;
}

double calcScore(Stat s)
{
        
cout<<(s.getSum()- s.getMin()- s.getMax()) / 3 <<endl;
      
}
jrice528 20 Light Poster

Ok, i made a psot earlier but my code is alot different and different question so i didnt know where to put it.

My question is thiss... in my calcScore function. This is my requirement:
Design and implement a function double calcScore() that calculates and returns the average of the three scores that remain after dropping the highest and lowest scores a performer received. This function should be called once for each contestant by your function main(), and it should be passed the Stat object that contains the 5 scores from the judges.

I am having trouble of passing the values of score 1-5 into the calcScore function. If i didnt have to use the function it wouldnt be a problem. But I do, and i dont know how to do it.

#include "Stat.h"
#include <iostream>
using namespace std;

void getJudgeData(int &);
double calcScore();

int main()
{
    Stat s;
    int score1 = 0, score2 = 0, score3=0, score4=0, score5=0;
    

	cout << "This program assignment number 4 was created by Jeremy Rice" << endl;
	cout<<  "The Next American Idol!!!"<<endl;
    cout<< "Please enter your scores below!"<<endl; 

cout<< "Enter contestant #1's scores!"<<endl;
cout<<"Judge #1 what is your score"<<endl;
getJudgeData(score1);
s.setNum(score1);
cout<<"Judge #2 what is your score"<<endl;
getJudgeData(score2);
s.setNum(score2);
cout<<"Judge #3 what is your score"<<endl;
getJudgeData(score3);
s.setNum(score3);
cout<<"Judge #4 what is your score"<<endl;
getJudgeData(score4);
s.setNum(score4);
cout<<"Judge #5 what is your score"<<endl;
getJudgeData(score5);
s.setNum(score5);


cout<<"Talent score for contestant #1 is: "<<calcScore()<<endl;


system("pause");
	return 0;
}

void getJudgeData(int &getNum)
{
     Stat s; …
jrice528 20 Light Poster

Ok, i have been working on this program for a LONG time and i need some major help with the main.cpp file PLEASE.
I have to design a function that Designs and implements a function void getJudgeData() that asks the user for a judge's score, stores it in a reference parameter variable, and validates it. This function should be called by your function main() once for each of the 5 judges.

I dont get the reference parameter... Could anyone please please help me out i turned in the .cpp and .h files already and he said to not modify it anymore that it is good. To only work on the main.cpp and i need major help with the void getJudgeData part.


Main.cpp file

#include <iostream>
#include "Stat.h"

using namespace std;

void getJudgeData();
double calcScore();


int main()
{
    Stat s;

	cout << "This program assignment number 4 was created by Jeremy Rice" << endl;
	cout<<  "The Next American Idol!!!"<<endl;
    cout<< "Please enter your scores below!"<<endl; 

// asking for the scores from each judge
//using the function getJudgeData
cout<<"Judge #1 ";
getJudgeData();
cout<<"Judge #2 ";
getJudgeData();
cout<<"Judge #3 ";
getJudgeData();
cout<<"Judge #4 ";
getJudgeData();
cout<<"Judge #5 ";
getJudgeData();


system("pause");
	return 0;
}

void getJudgeData()
{
     Stat s;
    s.getNum("Please enter your score ");
  
 
}

double calcScore()
{
       Stat s;
       s.getAverage= (s.getSum - s.getMin - s.getMax)/3;
}

the idol.cpp file

#include <iostream> // for cin, cout
#include "Stat.h"

using namespace std;

Stat::Stat(  ){
    reset( );
}

void …
jrice528 20 Light Poster

Ok I am not gettin this, sorry for the ignorance, hehe first program using functions. What would i implement into main from here. Again sorry spent hours trying to figure this out and writing and rewriting the code, but i cant seem to get it right.

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

// Function prototype

unsigned getFlip();

int main()
{
// Variables   
    
   unsigned toss;
   unsigned heads = 0;
   unsigned tails = 0;
   srand(time(0));

cout<< "Please enter how many times you'd like to flip the coin"<<endl;
cin>> toss;

for (unsigned i = 0; i < toss; i ++)  
{ 

getFlip();

if (tails == 0)
   tails ++;
else
    heads++;
}

// How many times the coin hit heads and tails

cout<<"You have flipped tails "<<tails<<" times"<<endl;
cout<<"You have flipped heads "<<heads<<" times"<<endl;

//Initializing the time, and the total number of flips.

   unsigned total = 0;
   total = heads + tails;
   
time_t rawtime;
time ( &rawtime );
cout<<"The day of "<<ctime (&rawtime)<<"You flipped the coin "<<total;
cout<<" number of times"<<endl;

system("pause");
return 0;
    
}


// function flip
// returns 0 for tails and 1 for heads



unsigned getFlip()
{
    return (rand() % 2);
    
}
jrice528 20 Light Poster

I am so close to finsihing my homework im on last programmign assignment. I have the program written but i cant figure out what to take from main and put into my flip function. the teacher said it should only contain one lineof code. Anbody have any ideas?Which is :

Write a C++ program that uses the rand(), the srand(), and time() functions from the cstdlib and ctime libraries to simulate coin tossing. Your program should ask the user how many times the coin will be tossed. For each toss of the coin, the program should keep track of which side of the coin (e.g. Heads or Tails) appears, and it should count the total for each side. At the end ot tossing the coin the user-specified number of times, the program should print the results. The program should call a separate function named flip() that takes no arguments and returns 0 for tails and 1 for heads.

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

// Function prototype

unsigned getFlip();

int main()
{
// Variables   
    
   unsigned toss;
   unsigned heads = 0;
   unsigned tails = 0;
   srand(time(0));

cout<< "Please enter how many times you'd like to flip the coin"<<endl;
cin>> toss;

for (unsigned i = 0; i < toss; i ++)  
{ 
         if (rand() % 2)
  { 
         tails ++;
  }
         else
  {
         heads ++;
  }
    
}

// How many times the coin hit heads and tails

cout<<"You have flipped tails "<<tails<<" times"<<endl;
cout<<"You have flipped heads "<<heads<<" …
jrice528 20 Light Poster

Its for homework, he told us to use functions but no arguements... mmm ill ask him when i go to class, which i am leaving for now.

jrice528 20 Light Poster

I have one last question, I am running the program with the function flip()... I need the function flip() to return the value of heads and tails back into main, without using any arguments. sorry for the bother I either really messed up or something. Functions are hard for me to understand.

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
// using the function flip simulate a coin flipping
// user enters amount of times to flip the coin
// have your program return how many were tails 
// and how many were heads.


//Function Prototype flip
unsigned flip();
int main()
{
    
//Input number of times to flip the coin.
      cout<< "Enter the number of times you would like to flip the coin."<<endl;
//function flip 
  flip();

//Variables
           unsigned heads = 0;
           unsigned tails = 0;
           
        
       cout<< " You flips tails "<<tails<<" times"<<endl;
       cout<< " You flips heads "<<heads<<" times"<<endl;
                 
        
system("pause");
return 0;            
}


unsigned flip()
{
         
          unsigned heads = 0;
          unsigned tails = 0;
          unsigned flips;
          unsigned toss;
          
          srand(time(0));

cin>>toss;
flips = toss;

      for (int i = 0; i < toss; i ++)
{ 
  if (rand() % 2)
  { 
         heads ++;
  }
               else
  {
         tails ++;
  }
    
}

}
jrice528 20 Light Poster

thanks for all the help, I got the program to work without the function, just trying to do that now. Thnks!

jrice528 20 Light Poster

I enter say 55, and I only get output of 1 and 0.. instead of like 25 were heads and 25 were tails.. just says 1 is heads and 0 was tails.

jrice528 20 Light Poster

I need a user to enter the nubmer of times to flip the coin, then have it spit out how many were heads and tails. So like, I want to flip the coin 50 times. How many are heads and how many tails.

jrice528 20 Light Poster

This program was suppose to be with a function but I am trying to write without a function first, then adding one later. I am new to programming and still gettin basics. I got this much but its only giving me a 1 and a 0. Ive tried to find the fix, can you guys help me out please?

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
unsigned heads = 0;
unsigned tails = 0;
unsigned flips =  0;


cout<<"enter number of times to flip the coin."<<endl;
cin>>flips;
flips = rand() % 2;
for (int i = 0; i < flips; i ++)
{
if ( flips == 0 )
heads = heads ++;
else
tails ++;
}

cout<< " You flips tails "<<tails<<" times"<<endl;
cout<< " You flips heads "<<heads<<" times"<<endl;
system("pause");
return 0;
}
jrice528 20 Light Poster

I have written a binary to decimal program. I have several loops. I was wondering if there is a command... Say the user is done entering binary numbers, cause the program was supposed to be made by entering one at a time. ( homework ) Anyways, The user is done entering digits, is there a command that will skip all the other loops and go straight to the end of the program?

jrice528 20 Light Poster

I dont know if this will help or not. It is homework and ive spent 2 days on it getting absolutely no where. the teacher never even explained how to use modulus, and I am really really stuck trying to figure it out.

Write a program that reads in an unsigned integer containing only 0s and 1s (i.e. a "binary" integer) and outputs its decimal equivalent. Use the modulus and division operators to pick off the "binary" number's digits one at a time from rigiht to left.Your program must accept only (unsigned) "binary"integers containing only 0s and 1s. Do not read in the integer as a string object. Use a loop to validate the input: the user should get stuck entering a "binary" integer if the value entered is not of the right form.

jrice528 20 Light Poster

No, not as a string number,

I need to enter a binary "111" and have the output be equal 7...

What I mean by decimal form is i need to convert the binary number to the decimal number that us ut equivilant too. The only code I really have is what I posted above. Where I seperated the number into digits. I dont know how to take those binary digits and give them the decimal.

jrice528 20 Light Poster

this is as far as i have as to seperating it into digits, I dont know where to begin to take that digit, then assign it the decimal value

#include <iostream>

using namespace std;
int main()
{
    int num;
    cout<<"Enter a Number : ";
    cin>>num;

    for(; num ; num/=10)
        cout<<num%10<<endl;
    


system("pause");
}
jrice528 20 Light Poster

I read in the binary form "011010"
I having trouble getting it into digits, and assigning that digit the value in decimal form.

I can only use unsign, % and / ...

I am getting down how to divide into digits using %10, but i cant assign it the decimal form.

jrice528 20 Light Poster

I just started c++ and programming and need some major help. I am trying to convert binary to decimal. I have searched through everything and its all to hard for me to understand,and uses terms ive never seen.

I need to convert the binary to dec, using % and / and only unsigned numbers.

Does anybody have suggestions. I need help to type in "1000101" seperate it into digits and then assign that digit its decimal number. It needs to be simple again I amvery new and the stuff on here seems to advanced for me.