Hello :) I am in Computing Science 160 and need to do a C++ assignment. I need a program that reads in user input of strings (ex. PTLPPDNQL*) and stopping when a * is read. It then needs to read each letter as a value (P = pennie or 1 cent, T = toonie or 200 cents, etc). This is the part I need help with. Do I need to use an if or while statement or something like that? I started with this, but not sure what to do now:
#include <iostream>
#include <iomanip>
using namespace std;
void getInput(int &ncoins, int &namount)
{
int P = 0;
int N = 0;
int D = 0;
int Q = 0;
int L = 0;
int T = 0;
char x;
cout << "Coin Count Program" << endl;
cout << "Enter the string of coins (terminated by a *): ";
cin >> x;
//This is where I'm stuck.... I can't break up the cin into something i can decipher. should it be something like a while (x != "8") and then a bunch of if statements to see which variable gets increased? please help
ncoins = (P + N + D + Q + L + T);
namount = (P + (N*5) + (D*10) + (Q*25) + (L*100) + (T*200));
}
void doCalculations(int namount, int &namountd, int &namountp)
{
namountd = (namount / 100);
namountp = (namount % 100);
}
void showOutput(int ncoins, int namountd, int namountp)
{
cout << "Total number of coins: " << ncoins << endl;
cout << "Total amount: $" << namountd << "." << setw(2) << setfill('0') <<namountp << endl;
}
int main()
{
int ncoins;
int namountd;
int namountp;
getInput(ncoins, namount);
doCalculations(ncoins,namountd, namountp);
showOutput(ncoins, namountd, namountp);
return 0;
}