Welcome to the Newschoolers forums! You may read the forums as a guest, however you must be a registered member to post. Register to become a member today!
lets see if the fancy editor will let me show the code
#include <iostream.h>
#include <math.h>
using namespace std;
int numpen, numnic, numdim, numqua, numloo, numtoo;
float pen, nic, dim, qua, loo, too, total;
main ()
{
cout << "Please enter how many pennies you have: ";
cin >> numpen;
cout << endl;
cout << "Please enter how many nickles you have: ";
cin >> numnic;
cout << endl;
cout << "Please enter how many dimes you have: ";
cin >> numdim;
cout << endl;
cout << "Please enter how many quarters you have: ";
cin >> numqua;
cout << endl;
cout << "Please enter how many loonies you have: ";
cin >> numloo;
cout << endl;
cout << "Please enter how many toonies you have: ";
cin >> numtoo;
cout << endl;
pen = numpen * 0.01;
cout << "You have " << pen << " cents worth of pennies.";
cout.precision(2);
cout << endl;
nic = numnic * 0.05;
cout << "You have " << nic << " cents worth of nickles.";
cout.precision(2);
cout << endl;
dim = numdim * 0.10;
cout << "You have " << dim << " cents worth of dimes.";
cout.precision(2);
cout << endl;
qua = numqua * 0.25;
cout << "You have " << qua << " cents worth of quaters.";
cout.precision(2);
cout << endl;
loo = numloo * 1.00;
cout << "You have " << loo << " dollars worth of loonies.";
cout.precision(2);
cout << endl;
too = numtoo * 2.00;
cout << "You have " << too << " dollars worth of toonies.";
cout.precision(2);
cout << endl;
cout << endl;
total = pen + nic + dim + qua + loo + too;
cout << "The total amount of money you have is " << total << " dollars.";
cout << "Press any key to continue: ";
cin.get();
}
This is a piece of code
cout << "Please enter your last name (max 14 characters): ";
cin.getline(name, 14);
Why the hell is it skipping this step?
I had it as:
cout << "Please enter your last name (max 14 characters): ";
cin >> name;
but it doesnt limit that string to 14 characters and it doesnt accept spaces.
So how do i make the cin.getline (name, 14) to work properly? It just skips the cin name phase, cout's the Next line, THEN it decides to allow me to type in but it doesnt assign it to the name varible.
Whats up?
ok so i said fuck it and went with this
cout << "Please enter your last name (max 14 characters, lower case, no spaces): ";
cin >> name;
but since char name[15]; it waits till all 14 characters are taken up (which is a bunch of enters. how can i tell it to stop that shit and when they hit enter to move on?
Im frustrated beyonf belief at this shitty program.
Problem: After i input the employee number, its propts for the last name, which i type in but when i hit enter nothing happens. I can hit enter 100 times and nothing. It wont move onto the hottub question.
here it is in all its shittiness:
#include <iostream.h>
#include <math.h>
int tubs;
int id;
float salary;
char name[15];
main()
{
cout << "Please enter your Employee ID number (5 digits): ";
cin >> id;
cout << "Please enter your last name (max 14 characters, lower case, no spaces): ";
cin >> name;
cout << "Please enter the number of hottubs sold: ";
cin.ignore('/n');
cin >> tubs;
cout << endl;
cout << id << endl << name << endl << tubs;
cout << endl;
}
#include
"stdafx.h"int
tubs;
int id;
float salary;
char name[15];int main()
{
cout << "Please enter your Employee ID number (5 digits): ";
cin >> id;
cout << "Please enter your last name (max 14 characters, lower case, no spaces): ";
cin >> name;
cout << "Please enter the number of hottubs sold: ";
//cin.ignore('/n');
cin >> tubs;
//cout << endl;
cout << id << endl << name << endl << tubs;
cout << endl;
return 0;
}
so i finally got the programing working :D
apperently the lone problem was this line
cin.ignore('/n');
had to be switched to
cin.ignore(10, '/n');
program runs perfectly now (i dont need error checking on it yet)