dimanche 24 février 2019

C++ program does not wait for user input before providing output

new here so sorry if I sound ignorant, I very much am. I am currently writing a program that would calculate the price of having a sign built based on the color of the font, the number of characters in the sign, and the type of wood. When compiled the program waits for user input to be provided for the color and for the number of characters but when it comes time to ask for the wood type the program asks the question and simply displays the price without allowing user input. Can someone help explain why and how I could possibly resolve this?

enter code here // HouseSign.cpp - This program calculates prices for custom made signs.

#include <iostream>
#include <string>
using namespace std;
int main()
{
int charge=0;
int numChars=8;
int color;
int woodType;
int premiumCharsPrice;
int gold;
int oak;

charge= charge + 35;

cout << "How many characters are in the sign?" << endl;
cin >> numChars;
if (numChars>5){
premiumCharsPrice=(numChars-5)*4;
charge=charge+premiumCharsPrice;
}

cout << "What color will the sign be?" << endl; 
cin >> color;
if (color=gold){
charge=charge+15;
}

cout << "What kind of wood will be used?" << endl; 
cin >> woodType;
if (woodType=oak){
charge=charge+20;
}

cout << "The charge for this sign is $" << charge << endl;
return(0); 
}   

Aucun commentaire:

Enregistrer un commentaire