:!: I'm very new to programing, been trying to write this coke machine program. Can anybody help me.

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int getcoins ()

{
int total = 0, number;
cout << "put in coins: ";
while (total < 65)
{
cin >> number;
if (number == 100) ;! (number == 25) ;! (number && 10) ;! (number & 5)
total; += number;
if (total < 65) cout << "add more coins:" << endl;
}

return total;
}

//function to see if selection is available bool checkselection (char * machine, char select)

{
bool isavailable = false;
for (int i = 0; i < 9; i++)
if (*(machine +i) == select) isavailable = true; //check if c s or d is available *(machine + i) = ' '; //change selected item to space to initiate that it is gone return isAvailable;
}
int main()

{
do I use char?
char "machine = ??ne char [10]
*(machine + 0) = 'c';
*(machine + 1) = 'c';
*(machine + 2) = 'c';
*(machine + 3) = 's';
*(machine + 4) = 's';
*(machine + 5) = 's';
*(machine + 6) = 'd';
*(machine + 7) = 'd';
*(machine + 8) = 'd';

cout << "\t\t **********************" << endl;
cout << "\t\t\tTony's HIP POP SODA MACHINE" << endl;
cout << "\t\t **********************" << endl << endl

cout << "make selection c for Coke, s for Sprite, d for Dr. Pepper:";
cin >> select;
if ('checkselection (machine, select);
cout << "your chnage is " << change << "cents:" << endl;

cout << getcoins() << endl;
return 0;
}

I'm in a kind of hurry, but

if (number == 100)  ;! (number == 25) ;! (number && 10) ;! (number & 5)

should be something like

if (number == 100 || number == 25 || number == 10 || number == 5)

As far as I know is & the adress of the variable operator, and not an iterator (hope I'm using the right terms here). TO did I thought that && wasn't an iterator.

:!: I'm very new to programing, been trying to write this coke machine program. Can anybody help me.

#include<iostream>

using std::cout;
using std::cin;
using std::endl;

int getcoins ()

{
int total = 0, number;
      cout << "put in coins: "; // put in while loop
while (total < 65)
      {
            cin >> number;
if (number == 100)  ;! (number == 25) ;! (number && 10) ;! (number & 5)
                  total; += number; // stray semicolon

// no need for below stmt
// if (total < 65) cout << "add more coins:"  << endl; 
      }

return total;
}

//function to see if selection is available bool checkselection (char * machine, char select)

{
bool isavailable = false;
for (int i = 0; i < 9; i++)
if (*(machine +i) == select) isavailable = true; //check if c s or d is available *(machine + i) = ' '; //change selected item to space to initiate that it is gone return isAvailable;
}
int main()

{
// try a constant size char array for what you want
 
char machine[9]  ; 
// *(machine + 0) = 'c'; // no need of ptr syntax just use normal array one
machine [0] = 'c' ;
// or initialise and declare at same time

char machine[] = {'c', 'c', 'c', 's', 's', 'd', 'd', 'd', 'd', 'd'} ;
cout << "\t\t **********************" << endl;
cout << "\t\t\tTony's HIP POP SODA MACHINE" << endl;
cout << "\t\t **********************" << endl << endl

            cout << "make selection c for Coke, s for Sprite, d for Dr. Pepper:";
            cin >> select;
if ( ' checkselection (machine, select) ; // stray semicolon and tilde 
                  cout << "your chnage is " << change << "cents:" << endl;

cout << getcoins() << endl;
return 0;
      }

There are a lot of syntax errors in your program. If you are still new on C++ you can try out the free tuts out there or buy a good book to get a good hold of the basics. The problems are marked by me in red.

This article has been dead for over six months. Start a new discussion instead.